WPF触发器改变光标 [英] WPF Trigger to change Cursor

查看:341
本文介绍了WPF触发器改变光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改触发器中的TreeViewItem的游标。此代码适用于所有其他属性,但不适用于Cursor:

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?

推荐答案

你做的正确,它应该工作。实际上,我无法通过以下步骤重现您的问题:

You are doing it correctly, it should just work. In fact I'm unable to reproduce your issue via the following steps:


  • 通过VS 2008 C#WPF应用程序向导创建了一个新项目。


    • 产生App.xaml和Window1.xaml

    好吧,这只是工作正常,即一旦悬停在一个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.

    一个重要的细节:光标只会在将标题直接悬停在标题上时出现,即整行与WPF TreeViewItem行行为一致,但请参阅相关示例的此处行突出显示)。特别是当TeeViewItem标题为空时,光标会出现!您是否为标头提供了任何数据?

    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?

    这篇关于WPF触发器改变光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆