I am attempting to expand a Child Node when its parent is expanded.
Otherwise stated: (Child.IsExpanded == Parent.IsExpanded)
This appears right, but does not seem to work:
<TreeView ItemsSource="{Binding}">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Style.Triggers>
<DataTrigger Value="True"
Binding="{Binding Path=IsExpanded,
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type TreeViewItem},
AncestorLevel=2}}">
<Setter Property="IsExpanded" Va开发者_运维知识库lue="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Neither does this:
<TreeView ItemsSource="{Binding}">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded"
Value="{Binding Path=IsExpanded,
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type TreeViewItem},
AncestorLevel=2}}" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
What's missing here?
Thanks in advance.
Both work for me. If you tested it with static TreeViewItems
make sure to apply the style via resources, the ItemContainerStyle
is only relevant for dynamically created containers. Also note that user-interaction may set a local value, overriding those styles.
精彩评论