[Solved] WPF C# Bind multiple treeViewItems isSelected to tabItem isSelected


using SelectedValue and SelectedValuePath.

The TreeViewItem child and parent must have the same Uid.

<Window x:Class="WpfApp1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel>
        <TreeView x:Name="treeView" Height="200" SelectedValuePath="Uid">
        
            <TreeViewItem Header="Letters-1" x:Name="tab1" Uid="Letters-1">
                <TreeViewItem Header="a" Uid="Letters-1"/>
                <TreeViewItem Header="b" Uid="Letters-1"/>
                <TreeViewItem Header="c" Uid="Letters-1"/>
            </TreeViewItem>
        
            <TreeViewItem Header="Letters-2" x:Name="tab2" Uid="Letters-2">
                <TreeViewItem Header="d" Uid="Letters-2"/>
                <TreeViewItem Header="e" Uid="Letters-2"/>
                <TreeViewItem Header="f" Uid="Letters-2"/>
            </TreeViewItem>
        
            <TreeViewItem Header="Letters-3" x:Name="tab3" Uid="Letters-3">
                <TreeViewItem Header="g" Uid="Letters-3"/>
                <TreeViewItem Header="h" Uid="Letters-3"/>
                <TreeViewItem Header="i" Uid="Letters-3"/>
            </TreeViewItem>
        
        </TreeView>
    
        <TabControl x:Name="tabControl" Height="100"
                    SelectedValuePath="Header"
                    SelectedValue="{Binding ElementName=treeView, Path=SelectedValue, Mode=OneWay}">
        
            <TabItem Header="Letters-1"/>

            <TabItem Header="Letters-2"/>

            <TabItem Header="Letters-3"/>

        </TabControl>
    </StackPanel>
</Window>

0

solved WPF C# Bind multiple treeViewItems isSelected to tabItem isSelected