Hi!
I´m trying to bind a collection of custom objects to a RadTreeListView. The object represents a `User`, who have a collection of different rights and a collection of log entries.
How can i define the section "Rights/Log Entries" within a HierarchicalDataTemplate? I´ve tried it based on your tutorial on binding collections.
My Version of Telrik WPF is the current public release.
The structure i would like to achieve should look like this:
User 1
Rights
Right 1
Right 2
Log Entries
Entry 1
Entry 2
User 2
Rights
Right 1
Log Entries
...
XAML:
I´m trying to bind a collection of custom objects to a RadTreeListView. The object represents a `User`, who have a collection of different rights and a collection of log entries.
How can i define the section "Rights/Log Entries" within a HierarchicalDataTemplate? I´ve tried it based on your tutorial on binding collections.
My Version of Telrik WPF is the current public release.
The structure i would like to achieve should look like this:
User 1
Rights
Right 1
Right 2
Log Entries
Entry 1
Entry 2
User 2
Rights
Right 1
Log Entries
...
public sealed class User{ public string Firstname { get; set; } public string Lastname { get; set; } public ObservableCollection<Right> Rights { get; set; } public ObservableCollection<LogEntry> LogEntries { get; set; } public User(string firstname, string lastname) { this.Firstname = firstname; this.Lastname = lastname; this.Rights = new ObservableCollection<Right>(); this.LogEntries = new ObservableCollection<LogEntry>(); }}public sealed class RightsCollection{ public RightsCollection() { this.Name = "Rights"; this.Rights = new ObservableCollection<Right>(); } public string Name { get; set; } public ObservableCollection<Right> Rights { get; set; }}public sealed class Right{ public string Name { get; set; } public string Description { get; set; } public bool Value { get; set; } public Right(string name) { this.Name = name; this.Description = String.Empty; this.Value = true; } public Right(string name, string description) : this(name) { this.Description = description; } public Right(string name, string description, bool value) : this(name, description) { this.Value = value; }}XAML:
<UserControl.Resources> <local:Users x:Key="UserCollection" /> <HierarchicalDataTemplate x:Key="Right"> <TextBlock Text="{Binding Name}" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="Rights" ItemTemplate="{StaticResource Right}" ItemsSource="{Binding Rights}"> <TextBlock Text="{Binding Name}" /> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="Users" ItemTemplate="{StaticResource Rights}" ItemsSource="{Binding Rights}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Lastname}" /> <TextBlock Text=", " /> <TextBlock Text="{Binding Firstname}" /> </StackPanel> </HierarchicalDataTemplate> </UserControl.Resources><telerik:RadTreeView IsLineEnabled="True" ItemsSource="{Binding Source={StaticResource UserCollection}}" ItemTemplate="{StaticResource Users}" />