This question is locked. New answers and comments are not allowed.
Hi
I tried to follow you example with the DataItem class. I add a couple of properties (in order to make the DataItem class relevant to my application) and I built the tree just as in your samples.
Now I'm trying to bind a value from the DataItem class ( a boolean property) to the IsChecked value of the CheckBox in each of the elements in the tree.
I'm using a DataTemplate with a CheckBox and a TextBlock. Here is the template definition:
public class DataItem
{
ConfigSectiob m_element;
public ConfigSection Element
{
get{return m_element;}
set{m_element = value; }
}
public string Name {get; ,set;}
public bool Checked {get; ,set;}
public List<DataItem> Items {get; ,set;}
public DataItem()
{
this.Items = new List<DataItem>()
}
}
I tried to follow you example with the DataItem class. I add a couple of properties (in order to make the DataItem class relevant to my application) and I built the tree just as in your samples.
Now I'm trying to bind a value from the DataItem class ( a boolean property) to the IsChecked value of the CheckBox in each of the elements in the tree.
I'm using a DataTemplate with a CheckBox and a TextBlock. Here is the template definition:
public class DataItem
{
ConfigSectiob m_element;
public ConfigSection Element
{
get{return m_element;}
set{m_element = value; }
}
public string Name {get; ,set;}
public bool Checked {get; ,set;}
public List<DataItem> Items {get; ,set;}
public DataItem()
{
this.Items = new List<DataItem>()
}
}
My problem is that the binding proccess does not work and I get error at runtime. I attached the DataItem class code too.
| private void InstantiateTemplates() | |
| { | |
| string s1 = @" | |
| <DataTemplate x:Name=""LayoutRoot"" | |
| xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" | |
| xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" | |
| xmlns:telerik=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"" | |
| xmlns:telerikNavigation=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation""> | |
| <CheckBox IsChecked=""{Binding Checked}"" /> | |
| <TextBlock Text=""{Binding Names}""/> | |
| </DataTemplate> | |
| "; | |
| string s2 = @" | |
| <telerik:HierarchicalDataTemplate ItemsSource=""{Binding Items}"" | |
| xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" | |
| xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" | |
| xmlns:telerik=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"" | |
| xmlns:telerikNavigation=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation""> | |
| <CheckBox IsChecked=""{Binding Checked}"" /> | |
| <TextBlock Text=""{Binding Names}""/> | |
| </telerik:HierarchicalDataTemplate> | |
| "; | |
| string s3 = @" | |
| <telerik:HierarchicalDataTemplate ItemsSource=""{Binding Items}"" | |
| xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" | |
| xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" | |
| xmlns:telerik=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"" | |
| xmlns:telerikNavigation=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation""> | |
| <CheckBox IsChecked=""{Binding Checked}"" /> | |
| <TextBlock Text=""{Binding Names}"" /> | |
| </telerik:HierarchicalDataTemplate> | |
| "; | |
| this.dataTemplate2 = (DataTemplate)XamlReader.Load(s1); | |
| this.subItemTemplate2 = (HierarchicalDataTemplate)XamlReader.Load(s2); | |
| this.subItemTemplate2.ItemTemplate = this.dataTemplate2; | |
| this.itemTemplate2 = (HierarchicalDataTemplate)XamlReader.Load(s3); | |
| this.itemTemplate2.ItemTemplate = this.subItemTemplate2; | |
| } | |
| List<DataItem> items; | |
| public List<DataItem> Items | |
| { | |
| get { return items; } | |
| set { items = value; } | |
| } |
|
| public Page() | |
| { | |
| InitializeComponent(); | |
|
items = new List<DataItem>();
this.InstantiateTemplates();
|
|
| telerikTreeView.ItemsSource = Items; | |
| telerikTreeView.ItemTemplate = this.itemTemplate2; | |
| telerikTreeView.ItemsOptionListType = OptionListType.CheckList; | |
| telerikTreeView.IsOptionElementsEnabled = true; } |
|
| |
|
Do you have any idea?
Thanks