我有以下xaml:
<ListView.ItemTemplate>
<DataTemplate>
<Border x:Name="SetBorder" Background="Transparent">
<Grid Margin="5" Width="130">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Source="{Binding Path=Code, Converter={StaticResource SetCodeToImageConverter}}" MaxWidth="105">
<Image.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=SetBorder, Path=Selector.IsSelectionActive}" Value="True">
<Setter Property="Image.Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=SetBorder, Path=IsMouseOver}" Value="True">
<Setter Property="Image.Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=SetBorder, Path=IsMouseOver}" Value="False">
<Setter Property="Image.Opacity" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Text="{Binding Path=Name}" TextWrapping="WrapWithOverflow" MaxWidth="120">
</TextBlock>
</Grid>
</Border>
</DataTemplate>
我希望当鼠标结束时(该部分有效)以及选择该项目时该图像的不透明度设置为1(该部分不起作用)。有什么想法吗?
答案 0 :(得分:0)
试试这个
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType= {x:Type ListBoxItem}, Path=IsSelected}" Value="True">
<Setter Property="Image.Opacity" Value="1" />
</DataTrigger>
我没有尝试过,但它应该有效