I need to create a TreeView in WPF that looks something like this:
- Admins (Group)
- Users (Fixed Node)
- Alice Adams (User)
- Bob Brown (User)
- Permissions (Fixed Node)
- Delete (Permission)
- Update (Permission)
- Users (Fixed Node)
- Guests (Group)
- Users (Fixed Node)
- Charlie Clarke (User)
- Permissions (Fixed Node)
- View (Permission)
- Users (Fixed Node)
I have a list of Groups, and each group has 3 properties:
- Name (string)
- Users (List)
- Permissions (List)
Displaying just the Users or Permissions is easy:
<TreeView ItemsSource="{Binding Groups}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Users}">
<TextBlock Text="{Binding GroupName}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding UserName}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
But I need to add 2 nodes (Users and Permissions) which expand to display the 2 list.
Any suggestions greatly appreciated…
You could use a MultiBinding with a converter to do something like this:
The converter would just give back the lists unmodified as
IEnumerable<T>.