项目需求,ListBox选中切换其选中项的Image控件的图片,其它每项ListBoxItem的相应Image控件都设置为未选中图片.
解决方案适用于ComboBox等:
1.先看xaml文件:
<DataTemplate x:Name="BusTemplate" x:Key="LBDataTemplate">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="{Binding BusStr}" VerticalAlignment="Center" FontSize="30" Foreground="White" Width="360"/>
<Image x:Name="BusStausImage" Source="/Image/d1.png"/>
</StackPanel>
</StackPanel>
</DataTemplate>
<ListBox ItemsSource="{Binding}" x:Name="BusList" SelectionChanged="ListBox_SelectionChanged" ItemTemplate="{StaticResource LBDataTemplate}">
2.现在要获取上面LisxBox的所有动态绑定项中的控件集合,然后全部换成默认图片。然后把当前选择项的Image换成选中样式的图片
<Image x:Name="BusStausImage" Source="/Image/1.png"/>
3.注册Lis