views:

1057

answers:

1

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?

A: 

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?

Steffen Opel