1

我有一个让我发疯的问题,我似乎无法找到解决方案。

我有一个 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 的第一个用户控件的依赖属性,并且超链接的样式位于单独的资源字典中。

任何帮助都感激不尽

4

1 回答 1

3

当控件没有获得焦点时,嗯 Selector.IsSelectionActive 是假的吗?如果是这样,也许您可​​以在列表视图上使用祖先绑定并检查焦点?

现在我查看了它 - 您正在绑定到附加属性 - 语法略有改变 - 请尝试使用 Path=(Selector.IsSelectionActive)} 代替。

绿色链接 - 奇怪:)

于 2010-11-09T13:01:52.650 回答