当我在列表框中选择项目时,下面的代码不起作用,你知道为什么吗?
<ListBox BorderBrush="Transparent" Background="Transparent" Name="listbox" HorizontalAlignment="Center" VerticalAlignment="Center" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="selection_changed">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Height="90" Width="150" Template="{StaticResource cbutton}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
模板 cbutton 看起来像这样
<ControlTemplate x:Key="cbutton" TargetType="Button">
<Border CornerRadius="3" BorderThickness="3.5" BorderBrush="White">
<Border.Background>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="DarkOrange" Offset="0.1"/>
<GradientStop Color="Orange" Offset="0.85"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock FontWeight="ExtraBold" Foreground="White" TextAlignment="Center" TextWrapping="Wrap" FontSize="15" Text="{Binding name}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>