我有一个让我发疯的问题,我似乎无法找到解决方案。
我有一个 Listview,其中 listivew ItemTemplate 是一个看起来像这样的数据模板:
<DataTemplate x:Key="template" >
<TextBlock Foreground="Green" >
<Hyperlink Command="{Binding LoadReportCommand}"
CommandParameter="{Binding DisplayName}" >
<TextBlock Text="{Binding DisplayName}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
超链接的样式如下:
<Style x:Key="{x:Type Hyperlink}" TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="Green" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True" />
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=Selector.IsSelectionActive}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="White"/>
</MultiDataTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</Style.Triggers>
</Style>
当我按原样使用它时,它不会像选择项目时预期的那样将前景变为白色。如果该命令未按预期启用,它确实会将前景变为灰色。如果我删除 Selector.IsSelectionActive 的条件,它会在项目被选择时将前景变为白色,但如果项目被选中但未激活,它也是白色的......我希望非活动选择为绿色。我也只用一个平面文本块尝试过这个,一个具有非常基本样式的按钮......似乎没有任何效果。
列表视图位于另一个用户控件中使用的用户控件中。数据模板位于第二个用户控件的资源字典中,并绑定到类型为 DataTemplate 的第一个用户控件的依赖属性,并且超链接的样式位于单独的资源字典中。
任何帮助都感激不尽