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

Possible bug with setting IsCheck property in style definition

2 Answers 39 Views
TreeView
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
Hi,

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"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
   mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
     
     
    <UserControl.Resources>
        <telerik:HierarchicalDataTemplate x:Key="TreeTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" Margin="2" VerticalAlignment="Center" />
            </StackPanel>
        </telerik:HierarchicalDataTemplate>
 
        <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" />
        </Style>
 
    </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
        <telerikNavigation:RadTreeView x:Name="LayerTree"
                                       HorizontalAlignment="Stretch"
                                       VerticalContentAlignment="Stretch"
                                       ItemTemplate="{StaticResource TreeTemplate}"
                                       ItemContainerStyle="{StaticResource TreeItemStyle}"
                                       ItemsSource="{Binding Path=Layers}"
                                       IsExpandOnSingleClickEnabled="True"
                                       IsLineEnabled="True"
                                       ItemsOptionListType="CheckList"
                                       IsOptionElementsEnabled="True"
                                       IsRootLinesEnabled="True"
                                       IsTriStateMode="True"
                                       SelectionMode="Extended"
                                       IsEditable="False">
 
            <telerikNavigation:RadTreeView.ItemEditTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Name, Mode=TwoWay}" />
                </DataTemplate>
            </telerikNavigation:RadTreeView.ItemEditTemplate>
 
        </telerikNavigation:RadTreeView>
 
    </Grid>
</UserControl>

2 Answers, 1 is accepted

Sort by
0
Accepted
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.

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