0

‘SelectedItem’ property is read-only and cannot be set from markup. How i can get selected item?

        <TreeView x:Name="TreeView1"
              ItemsSource="{Binding Path=Champ}">

        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type self:SimpleChampionship}" ItemsSource="{Binding Path=Tours}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Name}" />
                </StackPanel>
            </HierarchicalDataTemplate>
            <HierarchicalDataTemplate DataType="{x:Type self:SimpleTourClient}" ItemsSource="{Binding Path=Matches}">
                <StackPanel Orientation="Horizontal" >
                    <TextBlock Text="Tour:" />
                    <TextBlock Text="{Binding Path=NameTour}" />
                    <TextBlock Text=" Matches [" />
                    <TextBlock Text="{Binding Path=Matches.Count}" />
                    <TextBlock Text="]" />
                </StackPanel>
            </HierarchicalDataTemplate>
            <HierarchicalDataTemplate DataType="{x:Type self:SimpleMatchClient}">

                <StackPanel Orientation="Horizontal" >

                    <TextBlock Text="{Binding Path=Home}" />
                    <TextBlock Text="{Binding Path=HomeTeamGoals}" />
                    <TextBlock Text=" - " />
                    <TextBlock Text="{Binding Path=GuestTeamGoals}" />
                    <TextBlock Text="{Binding Path=Guest}" />
                </StackPanel>

            </HierarchicalDataTemplate>

        </TreeView.Resources>
    </TreeView>

example treeview

Need return selected SimpleMatchClient

Ugur
  • 1,257
  • 2
  • 20
  • 30
Venedchuk
  • 35
  • 6

1 Answers1

-1

Try this. It should work.

var treeViewItem = TreeView1.ItemContainerGenerator.ContainerFromItem(SelectedItem) as TreeViewItem;
ViVi
  • 4,339
  • 8
  • 29
  • 52