【问题标题】:Hyperlink Foreground styling in a listview not happening列表视图中的超链接前景样式未发生
【发布时间】:2011-05-07 05:31:54
【问题描述】:

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

我有一个 Listview,它的 listivew ItemTemplate 是一个 Datatemplate,看起来像这样:

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

任何帮助将不胜感激

【问题讨论】:

    标签: wpf xaml hyperlink datatemplate multidatatrigger


    【解决方案1】:

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

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

    绿色链接 - 奇怪:)

    【讨论】:

    • 你是我的英雄 :-) 添加括号非常感谢你:-)
    • @skitnica - 如果@Rune 确实是你的英雄,请将其标记为答案并投票给他...
    • 符文安徒生是我今天的英雄!!! (在我看到这个答案之前浪费了 4 个小时)
    猜你喜欢
    • 1970-01-01
    • 2020-01-13
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多