近段在做一个功能,在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&g