How to change TreeViewItem property from an element in its Header?
- by Jama64
I have a treeviewitem where the header property contains other elements such as TextBlock.
I want if the TextBlock Text = "Empty", the TreeViewItem not to be focasable.
Here I set the TextBox Focasable property but the containing TreeViewItem is focasable.
I want the TreeViewItem containing the TextBlock with the Text="Empty" not to be focasable.
Thanks
Here is my attempt.
<Grid>
<TreeView>
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="John">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="Empty">
<Setter Property="Background" Value="Red" />
<Setter Property="Focusable" Value="False"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</TreeViewItem.Header>
</TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock Text="Empty">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="Empty">
<Setter Property="Background" Value="Red" />
<Setter Property="Focusable" Value="False"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</TreeViewItem.Header>
</TreeViewItem>
</TreeView>
</Grid>