Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Trigger to change 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?

like image 212
Kamiikoneko Avatar asked Jul 15 '09 18:07

Kamiikoneko


1 Answers

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?

like image 62
Steffen Opel Avatar answered Nov 11 '22 23:11

Steffen Opel