Possible bug with setting IsCheck property in style definition

3 posts, 1 answers
  1. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 21 Mar 2011 Link to this post


    I'm trying to set checked state of TreeView items based on a bool property in the databound objects as described here (for WPF): http://www.telerik.com/help/wpf/radtreeview-how-to-bind-selected-item.html

    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. Answer
    Petar Mladenov
    Petar Mladenov avatar
    2992 posts

    Posted 22 Mar 2011 Link to this post

    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
  3. Alex Galie
    Alex Galie avatar
    22 posts
    Member since:
    Dec 2009

    Posted 22 Mar 2011 Link to this post

    Thanks Petar, I didn't know that :)
Back to Top