This is a migrated thread and some comments may be shown as answers.

Possible bug with setting IsCheck property in style definition

2 Answers 41 Views
This is a migrated thread and some comments may be shown as answers.
Alex Galie
Top achievements
Rank 2
Alex Galie asked on 21 Mar 2011, 06:38 PM

I'm trying to set checked state of TreeView items based on a bool property in the databound objects as described here (for WPF):

This doesn't seem to work in Silverlight. The workaround for this is to use the CheckState property instead and create a converter but I'd rather bind to a bool property, it's just cleaner like that.

I've created a simple project around this issue with just a TreeView but it won't let me attach it so here's the XAML:

<UserControl x:Class="SilverlightApplication1.MainPage"
    d:DesignHeight="300" d:DesignWidth="400">
        <telerik:HierarchicalDataTemplate x:Key="TreeTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" Margin="2" VerticalAlignment="Center" />
        <Style TargetType="telerikNavigation:RadTreeViewItem" x:Key="TreeItemStyle">
            <Setter Property="IsExpanded" Value="True" />
            <!-- THOSE DON'T WORK -->
            <Setter Property="IsChecked" Value="True" />
            <!--<Setter Property="IsChecked" Value="{Binding Path=IsVisible}" />-->
            <!-- THIS WORKS -->
            <!--<Setter Property="CheckState" Value="On" />-->
            <Setter Property="HorizontalAlignment" Value="Left" />
        <Grid x:Name="LayoutRoot" Background="White">
        <telerikNavigation:RadTreeView x:Name="LayerTree"
                                       ItemTemplate="{StaticResource TreeTemplate}"
                                       ItemContainerStyle="{StaticResource TreeItemStyle}"
                                       ItemsSource="{Binding Path=Layers}"
                    <TextBox Text="{Binding Name, Mode=TwoWay}" />

2 Answers, 1 is accepted

Sort by
Petar Mladenov
Telerik team
answered on 22 Mar 2011, 10:14 AM
Hi Alex Galie,

Binding a container property to a property of your ViewModel (business object) cannot be achieved with Style in Silverlight 4 (Probably it will be possible in SL5). For this purpose, we have created ContainerBindings. You can also find more info and comparison of IsChecked/CheckState in this blog post.Additionally you can examine the attached project where the basic approach is implemented.

Petar Mladenov
the Telerik team
Alex Galie
Top achievements
Rank 2
answered on 22 Mar 2011, 11:44 AM
Thanks Petar, I didn't know that :)
Asked by
Alex Galie
Top achievements
Rank 2
Answers by
Petar Mladenov
Telerik team
Alex Galie
Top achievements
Rank 2
Share this question