I would like to visualize the following data structure using TreeViews in WPF:
class MyDataContext { ICollectionView Outers {get;set;} //... } class Outer { string Name {get;set;} IEnumberable<Inner> Actions {get;set;} } class Inner { string Description {get;set;} Command OnClick {get;set;} }
This is my attempt:
<TreeView ItemsSource="{Binding Path=Outers}"> <TreeView.Resources> <DataTemplate DataType="{x:Type myns:Outer}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}"/> <TreeView ItemsSource="{Binding Path=Actions}" > <DataTemplate DataType="{x:Type myns:Inner}"> <Button Command={Binding Path=OnClick}> <TextBlock Text="{Binding Path=Description}"/> </Button> </DataTemplate> </TreeView> </StackPanel> </DataTemplate> </TreeView.Resources> </TreeView>
This seems like something is wrong with this access, since I get the following InvalidOperationException :
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
If I drop the internal TreeView, there is no exception (but also no buttons, of course).
source share