I'm looking for a TreeView structure of:
> {Name} {ParentButton}
> ParentData.Text
> {Name} {ChildButton}
> ChildData.Text
> {Name} {ChildButton}
> ...
> {Name} {ParentButton}
> ParentData.Text
> ...
I've come up with the following:
<TreeView ItemsSource="{Binding Models}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type models:ParentModel}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding ParentData.Name}"></Label>
<Button Content="MyParentButton" Command="{Binding ParentButton}"></Button>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type models:ChildModel}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding ChildData.Name}"></Label>
<Button Content="MyChildButton" Command="{Binding ChildButton}"></Button>
</StackPanel>
</HierarhicalDataTemplate>
</TreeView.Resources>
</TreeView>
ParentModel.cs
public class ParentModel {
public ParentOnlyObj ParentData { get; }
public ICommand ParentButton { get; }
public ObservableCollection<ChildModel> Children { get; }
}
ChildModel.cs
public class ChildModel {
public ChildOnlyObj ChildData { get; }
public ICommand ChildButton { get; }
public ObservableCollection<ChildModel> Children { get; }
}
With my attempt, I am getting:
> {Name} {ParentButton}
> ParentData.Text (?? how to add)
> {Name} {ChildButton}
> ChildData.Text (?? how to add)
> {Name} {ParentButton}
> ParentData.Text (?? how to add)
If the Models contains two ParentModel where the first contains one child.
That makes sense since I have not specified where Text is in the XAML. It's just that I'm confused on how to do that.
I am trying to have a TreeView items based on two models, but those two models must change the item's header as well as content, where the content may include further ChildModel.