This is what I have:
ObservableCollection<Item>()
ObservableCollection<Group> Groups = new ObservableCollection<Group>()
Each Group have a key, a name, a subgroup with the type ObservableCollection<Group>()
and a itemList
with type ObservableCollection<Item>()
.
My Treeview in the main window looks like this:
<TreeView Name="treeViewGroup" BorderThickness="0,2,0,0" ItemsSource="{Binding}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type data:Group}" ItemsSource="{Binding Items}">
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type data:ItemCollection}" >
//<StackPanel >
// <test:ucTable x:Name="table1" DataContext="{Binding IpAdress}">
// <TextBlock Text="{Binding Path=Name}" />
// </test:ucTable>
//</StackPanel>
</DataTemplate>
</TreeView.Resources>
The uc with the table looks like this:
<UserControl x:Class="namespace.GUI.ucTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Name="ucTable"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="500" >
<DataGrid x:Name="table1" Margin="10,10,10,10"
AutoGenerateColumns="False" CanUserAddRows="False"
CanUserReorderColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
AlternatingRowBackground="AliceBlue" Grid.IsSharedSizeScope="True">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Information"/>
<MenuItem Header="Delete"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" />
<DataGridTextColumn Header="Location" Binding="{Binding Location, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" />
<DataGridTextColumn Header="Ip" Binding="{Binding IpAdress, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
What I would like to have is a Treeview with all nested groups and if a group has a itemList with items the items should be in the usercontrol in the datagrid.
I tried a lot of examples and stuff but it doesn't work. Have someone an idea?
Thanks in advance