0

I'm working using WPF, and I'm dealing with the treeViewItem. I'm looking for a way to expand the node when the mouse is over this node, and set IsExpand=false property when the mouse is not over there. It's quite simple the functionality.

I'm a bit lost using the events for this controls, if should I use the triggers or the events. Thanks in advance.

1 Answer 1

2

Someting like this should point you in the right direction

<Grid>
    <TreeView Margin="0,40,0,0">
        <TreeViewItem Header="Level 1">
            <TreeViewItem Header="Level 2" />
        </TreeViewItem>

        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="False" />
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="IsExpanded" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
</Grid>
1
  • 1
    <Setter Property="IsExpanded" Value="{Binding Path=IsMouseOver, RelativeSource={RelativeSource Self}}" /> should work also.
    – Florian Gl
    Dec 12, 2012 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.