Hello i have a treeview which itemtemplate is checkbox. i want to get the selected items ischecked = true
how can i do this?
I want to get all the items selected in a list. Some items may have sub items
<TreeView x:Name="chkTree" ItemsSource="{Binding TreeRoot}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType = "{x:Type local:CheckTreeSource}" ItemsSource = "{Binding Children}">
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}"/>
<TextBlock Text="{Binding Text}"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
UPDATE:
i tried this but this work only if a item is selected with sub items, But if only sub-item is selected (the item itself is not selected only some of its sub-items) This code does not work
foreach (var item in chkTree.Items)
{
if (((CheckTreeSource)item).IsChecked== true && ((CheckTreeSource)item).Children !=null)
{
foreach (var subitem in ((CheckTreeSource)item).Children)
{
MessageBox.Show(((CheckTreeSource)subitem).Text + "");
}
}
}