WPF 触发器改变光标
我需要更改触发器中 TreeViewItem 的光标。 此代码适用于所有其他属性,但不适用于 Cursor:
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="QuickPhrases:TreeViewChecker.IsMouseDirectlyOverItem"
Value="True">
</Condition>
<Condition Property="CanSelect" Value="True"></Condition>
</MultiTrigger.Conditions>
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Foreground" Value="Blue"></Setter>
</MultiTrigger>
</Style.Triggers>
给出了什么,以及如何正确执行它?
I need to change the cursor of a TreeViewItem in a trigger. This code works for all other properties but not Cursor:
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="QuickPhrases:TreeViewChecker.IsMouseDirectlyOverItem"
Value="True">
</Condition>
<Condition Property="CanSelect" Value="True"></Condition>
</MultiTrigger.Conditions>
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Foreground" Value="Blue"></Setter>
</MultiTrigger>
</Style.Triggers>
What gives, and also, how do I do it correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做得正确,它应该可以工作。 事实上,我无法通过以下步骤重现您的问题:
TargetType="TreeViewItem"
的样式。嗯,这工作正常,即一旦将鼠标悬停在 TreeViewItem 上,光标就会被触发到我在触发器中选择的任何值,无论是“手”还是“等待”或其他。
但有一个重要的细节:光标仅在直接悬停在标题上方时出现,即而不是整个行(但这与 WPF TreeViewItem 行行为一致,请参阅 此处有关行突出显示的相关示例)。 特别是当 TeeViewItem 标题为空时,光标不会出现! 您是否已提供标题的任何数据?
否则,他们一定是在您的项目/环境的幕后发生了一些奇怪的事情? 您是否已经尝试过像这样的简单重现案例?
You are doing it correctly, it should just work. In fact I'm unable to reproduce your issue via the following steps:
TargetType="TreeViewItem"
.Well, this is just working fine, i.e. once hovering over a TreeViewItem the cursor gets triggered to whatever value I chose in the trigger, be it 'Hand' or 'Wait' or else.
One important detail though: the cursor only appears while hovering directly over the header, i.e. not the entire row (this is consistent with WPF TreeViewItem row behavior though, see here for a related example regarding row highlighting). Especially the cursor does not appear when the TeeViewItem header is empty! Have you supplied any data for the headers yet?
Otherwise their must be something weird going on behind the scenes in your project/environment? Have you tried a simple repro case like this already?