public partial class MainWindow : Window |
{ |
public MainWindow() |
{ |
InitializeComponent(); |
(Resources["DataSource"] as RadTreeViewSampleData).SelectedItem = (radTreeView.ItemsSource as IEnumerable<League>).LastOrDefault(); |
} |
} |
public class League : DependencyObject |
{ |
public League(string name) |
{ |
this.Name = name; |
this.Leagues = new List<League>(); |
} |
public string Name |
{ |
get; |
set; |
} |
public List<League> Leagues |
{ |
get; |
set; |
} |
} |
public class RadTreeViewSampleData : DependencyObject |
{ |
/// <summary> |
/// Identifies the SelectedItem dependency property. |
/// </summary> |
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(League), typeof(RadTreeViewSampleData)); |
/// <summary> |
/// Gets or sets SelectedItem. This is a dependency property. |
/// </summary> |
public League SelectedItem |
{ |
get { return (League)GetValue(SelectedItemProperty); } |
set { SetValue(SelectedItemProperty, value); } |
} |
public RadTreeViewSampleData() |
{ |
this.InitializeLeaguesDataSource(); |
} |
public List<League> LeaguesDataSource |
{ |
get; |
set; |
} |
private void InitializeLeaguesDataSource() |
{ |
this.LeaguesDataSource = new List<League>(); |
League l; |
League d; |
this.LeaguesDataSource.Add(l = new League("League A")); |
} |
} |
<Window.Resources> |
<local:RadTreeViewSampleData x:Key="DataSource"/> |
</Window.Resources> |
<telerik:RadTreeView x:Name="radTreeView" ItemsSource="{Binding Path=LeaguesDataSource, Source={StaticResource DataSource}}" SelectedItem="{Binding Path=SelectedItem, Source={StaticResource DataSource}, Mode=TwoWay}"> |
<telerik:RadTreeView.ItemTemplate> |
<HierarchicalDataTemplate ItemsSource="{Binding Path=Leagues}"> |
<TextBlock Text="{Binding Path=Name}" /> |
</HierarchicalDataTemplate> |
</telerik:RadTreeView.ItemTemplate> |
</telerik:RadTreeView> |