Hello,
I'm new in Telerik, and I have spent a very long time trying to solve a problem concerning the fact of using Container Bindings to manage checkboxes state in a TreeView.
So, I have a RadTreeView with a checklist items. I want the checkboxes in front of each items to be checked or not, depending on the values of the IsChecked property in my Business Objects.
I read on the Internet that the best way to do that was using a Container Binding. That's what I'm doing, but it doesn't work.
My Business Objects are
Then, in the XAML view, I do that :
<telerik:ContainerBindingCollection x:Name="BindingsCollection">
<telerik:ContainerBinding PropertyName="CheckState" Binding="{Binding IsChecked, Mode=TwoWay, Converter={StaticResource CheckStateConverter}}" />
</telerik:ContainerBindingCollection>
<telerik:HierarchicalDataTemplate
x:Key="MoOperation"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
<TextBlock Text="{Binding OperationId}" />
</telerik:HierarchicalDataTemplate>
<telerik:HierarchicalDataTemplate
x:Key="MoIModule"
ItemTemplate="{StaticResource MoOperation}"
ItemsSource="{Binding OperationsList}"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
<TextBlock Text="{Binding Name}" />
</telerik:HierarchicalDataTemplate>
</telerikNavigation:RadWindow.Resources>
And, in the code behind, I have the following converter :
public class CheckStateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool result = (bool)value;
return result ? ToggleState.On : ToggleState.Off;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ToggleState state = (ToggleState)value;
return state == ToggleState.On ? true : false;
}
}
When I test, the items are correctly loaded, but the checkboxes still empty. The converter isn't even called...
It seems to be quitly the same thing as we can read on the several examples with Container Bindings in TreeView, so I really don't know the origin of the problem.
Thanks for your help,
Sancho
I'm new in Telerik, and I have spent a very long time trying to solve a problem concerning the fact of using Container Bindings to manage checkboxes state in a TreeView.
So, I have a RadTreeView with a checklist items. I want the checkboxes in front of each items to be checked or not, depending on the values of the IsChecked property in my Business Objects.
I read on the Internet that the best way to do that was using a Container Binding. That's what I'm doing, but it doesn't work.
My Business Objects are
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace BusinessObjects.Entities.Security
{
[DataContract]
public class MoIModule
{
[DataMember]
public string Name { get; set; }
[DataMember]
public List<MoOperation> OperationsList { get; set; }
[DataMember]
public bool IsChecked { get; set; }
public MoIModule()
{
this.IsChecked = true;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace BusinessObjects.Entities.Security
{
[DataContract]
public class MoOperation
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string OperationId { get; set; }
[DataMember]
public string RoleId { get; set; }
[DataMember]
public bool IsChecked { get; set; }
public MoOperation()
{
this.IsChecked = true;
}
}
}
So, they have a boolean IsChecked property, which is set to true by default for testing.Then, in the XAML view, I do that :
<telerik:ContainerBindingCollection x:Name="BindingsCollection">
<telerik:ContainerBinding PropertyName="CheckState" Binding="{Binding IsChecked, Mode=TwoWay, Converter={StaticResource CheckStateConverter}}" />
</telerik:ContainerBindingCollection>
<telerik:HierarchicalDataTemplate
x:Key="MoOperation"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
<TextBlock Text="{Binding OperationId}" />
</telerik:HierarchicalDataTemplate>
<telerik:HierarchicalDataTemplate
x:Key="MoIModule"
ItemTemplate="{StaticResource MoOperation}"
ItemsSource="{Binding OperationsList}"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
<TextBlock Text="{Binding Name}" />
</telerik:HierarchicalDataTemplate>
</telerikNavigation:RadWindow.Resources>
And, in the code behind, I have the following converter :
public class CheckStateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool result = (bool)value;
return result ? ToggleState.On : ToggleState.Off;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ToggleState state = (ToggleState)value;
return state == ToggleState.On ? true : false;
}
}
When I test, the items are correctly loaded, but the checkboxes still empty. The converter isn't even called...
It seems to be quitly the same thing as we can read on the several examples with Container Bindings in TreeView, so I really don't know the origin of the problem.
Thanks for your help,
Sancho