开发者

Customize Expander to expand on mouse enter

开发者 https://www.devze.com 2023-03-11 01:27 出处:网络
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.

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开发者_C百科 I move away?


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.)


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

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

精彩评论

暂无评论...
验证码 换一张
取 消