WPF Trigger to change Cursor

穿精又带淫゛_ 提交于 2019-12-07 03:07:57

问题


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?


回答1:


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

  • Created a new project via VS 2008 C# WPF application wizard.
    • resulting in App.xaml and Window1.xaml
  • Added a standard TreeView from the toolbox to Window1.
  • Added 2 TreeViewItems '1' and '2'.
  • Added a Style with TargetType="TreeViewItem".
  • Pasted your snippet as is, but modified the conditions to something local of course.

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?



来源:https://stackoverflow.com/questions/1132971/wpf-trigger-to-change-cursor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!