近段在做一个功能,在ListBoxItem中点击Button 实现添加Item并选中最新添加项,把代码分享出来。
xaml:
<Window x:Class="WpfCustomerControl.ListBoxWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ListBoxWindow" Height="300" Width="300" WindowStartupLocation="CenterScreen" >
<Window.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
<Setter Property="Margin" Value="20,5,5,5"></Setter>
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid x:Name="

本文介绍如何在WPF应用中通过在ListBoxItem内嵌Button,实现在用户点击后动态添加新的ListBoxItem,并自动选中刚添加的项。提供了一段XAML代码示例。
最低0.47元/天 解锁文章
1342

被折叠的 条评论
为什么被折叠?



