How to change TreeViewItem property from an element in its Header?

Posted by Jama64 on Stack Overflow See other posts from Stack Overflow or by Jama64
Published on 2010-04-21T17:20:58Z Indexed on 2010/04/21 17:23 UTC
Read the original article Hit count: 209

Filed under:

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>

© Stack Overflow or respective owner

Related posts about wpf