首页 新闻 会员 周边 捐助

wpf listbox选中时修改图片

0
悬赏园豆:10 [已解决问题] 解决于 2018-05-20 15:15

想实现一个功能,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>

老牛在路上的主页 老牛在路上 | 初学一级 | 园豆:11
提问于:2018-04-15 17:57
< >
分享
最佳答案
0

不会用触发器,但是图片源绑定一个属性,当选中项改变时这个属性也改变是不是就行了

收获园豆:10
猝不及防 | 老鸟四级 |园豆:2836 | 2018-04-16 07:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册