列表视图中的超链接前景样式未发生
我有一个让我发疯的问题,而且我似乎无法找到解决方案。
我有一个 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 位于第二个用户控件的资源字典中,并绑定到 DataTemplate 类型的第一个用户控件的依赖属性,并且超链接的样式位于单独的 Resourcedictionary 中。
任何帮助将不胜感激
I have a problem that is driving me mad, and I just dont seem to be able to find a solution.
I have a Listview, for which the listivew ItemTemplate is a Datatemplate that looks like this:
<DataTemplate x:Key="template" >
<TextBlock Foreground="Green" >
<Hyperlink Command="{Binding LoadReportCommand}"
CommandParameter="{Binding DisplayName}" >
<TextBlock Text="{Binding DisplayName}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
The style for the hyperlink is as follows:
<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>
When I use it as is it does not turn the foreground white as would be expected when the item is selected. It does turn the foreground gray if the command is not enabled as is expected. If I remove the condition for Selector.IsSelectionActive it does turn the foreground white when the item is selection, but it is also white if the item is selected but not active.... I want the Inactive selection to be green. I have tried this also with just a plane Textblock, a button with a very basic style... nothing seems to work.
The listview is in a usercontrol that is used in another user control. The Datatemplate is in the resourcedictionary of the second user control, and bound to a dependency property of the first user control of type DataTemplate, and the style for the hyperlink is in a separate Resourcedictionary.
Any Help will be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,当控件没有获得焦点时,Selector.IsSelectionActive 是 false 吗?如果是这样,也许您可以在列表视图上使用祖先绑定并检查焦点?
现在我看看它 - 您正在绑定到附加属性 - 语法略有变化 - 尝试使用 Path=(Selector.IsSelectionActive)} 代替。
绿色链接 - 奇怪:)
Hmm Selector.IsSelectionActive is that false when the control hasn't got focus? If so maybe you could use an ancestorbinding on the listview and check for focus?
Now that I look at it - you are binding to an attached property - there is a slight changed syntax for that - try Path=(Selector.IsSelectionActive)} instead.
Green links - odd :)