想实现一个功能,listbox选中项改变时修改当前项图片,按以下方式图片不改变,请教各位大神该怎么改?
<Style x:Key="ss" TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Zfbl;component/resources/bllx.png"/>
<Style.Triggers>
<Trigger Property="ListBoxItem.IsMouseOver" Value="true">
<Setter Property="Source" Value="/Zfbl;component/resources/bllx_selected.png"/>
</Trigger>
<Trigger Property="ListBoxItem.IsSelected" Value="true">
<Setter Property="Source" Value="/Zfbl;component/resources/bllx_selected.png"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="UserItemContainerStyle" TargetType="ListBoxItem">
<!-- 设置控件模板 -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextBlock.Foreground="{TemplateBinding Foreground}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter Event="MouseDoubleClick" Handler="ListBox_MouseDoubleClick"></EventSetter>
<!-- 设置触发器 -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#eceff3"/>
<!--<Setter Property="Foreground" Value="White"/>-->
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="#eceff3"/>
<!--<Setter Property="Foreground" Value="Red"/>-->
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="ListBoxTemplate">
<Grid Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" ></ColumnDefinition>
<ColumnDefinition Width="30" ></ColumnDefinition>
<ColumnDefinition Width="auto" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Name="image" Style="{StaticResource ss}" Width="15" Height="15" Tag="1" Grid.Column="1"/>
<TextBlock Text="{Binding Name}" Width="auto" Height="auto" VerticalAlignment="Center" Grid.Column="2"/>
</Grid>
</DataTemplate>
不会用触发器,但是图片源绑定一个属性,当选中项改变时这个属性也改变是不是就行了