3

I am using Expander in WPF to display my data. The default style for the Expander control contains a toggle button which shows/hides my content when I click on it.

How can I modify the style so that it expands when I hovers the mouse over the header and collapse when I move away?

Metro
  • 1,121
  • 1
  • 13
  • 33
  • Hover (when the mouse lingers over the expander) or as soon as the mouse enters? – Liz Jun 06 '11 at 21:05

2 Answers2

7

Barebone setup should be this:

<Style TargetType="{x:Type Expander}">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="IsExpanded" Value="True" />
        </Trigger>
    </Style.Triggers>
</Style>

(Applies to the whole expander, not just the header. That would probably require messing with the template.)

H.B.
  • 166,899
  • 29
  • 327
  • 400
4

It is possible to use databinding between isExpanded property an ismouseover:

IsExpanded="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource Self}}"