Toggling IsOptionElementsEnabled messes with OptionType

4 posts, 1 answers
  1. Tobias Rodewi
    Tobias Rodewi avatar
    24 posts
    Member since:
    Apr 2010

    Posted 04 Aug 2011 Link to this post

    I've got a TreeView binding to a hierarchical collection of different types of objects. The template for each type is selected using a "standard" TemplateSelector and all of these templates are using the same ContainerBindings to set the OptionType, depending on the type of object (some should have check boxes, some OptionType.None).

    Now I also have a toggle button that enables/disables IsOptionElementsEnabled, but here's where things go wrong.

    If I set the toggle button to be checked when the elements load, it all works as it should, but when I toggle the button on/off, the OptionType is all forgotten for the TreeViewItems and the checkboxes show next to all the items (which it shouldn't).

    So what happends when toggling IsOptionElementsEnabled on the TreeView and how can I make the TreeViewItem.OptionType stick (or make it re-do the binding)?

    <telerik:ContainerBindingCollection x:Name="BindingsCollection">
        <telerik:ContainerBinding PropertyName="OptionType"
                                  Binding="{Binding Type, Converter={StaticResource TVITypeToOptionTypeConverter}, Mode=OneWay}" />
        <telerik:ContainerBinding PropertyName="IsSelected"
                                  Binding="{Binding IsSelected, Mode=TwoWay}" />
        <telerik:ContainerBinding PropertyName="IsExpanded"
                                  Binding="{Binding IsExpanded, Mode=TwoWay}" />
        <telerik:ContainerBinding PropertyName="IsEnabled"
                                  Binding="{Binding IsEnabled, Mode=TwoWay}" />

    public class TVITypeToOptionTypeConverter : IValueConverter
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            if (value is Enumerators.TVIType)
                switch ((Enumerators.TVIType) value)
                    case Enumerators.TVIType.Building:
                    case Enumerators.TVIType.Location:
                    case Enumerators.TVIType.TreeStructureItem:
                        return OptionListType.CheckList;
                        return OptionListType.None;
            return null;
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            return null;

    ToggleButton & TreeView
    <telerik:RadToggleButton x:Name="ComparisonToggle"
        <Image Source="/XXX.Infrastructure;Component/Resources/Images/scale.png" />
    <telerik:RadTreeView x:Name="treeView"
                         IsEnabled="{Binding CurrentlyFetchingData, Converter={StaticResource BooleanReverseConverter}}"
                         ExpanderStyle="{StaticResource ExpanderStyle}"
                         ItemsSource="{Binding TreeViewItems, Mode=OneWay}"
                         SelectedItem="{Binding SelectedTVI, Mode=TwoWay}"
                         ItemTemplateSelector="{StaticResource TemplateSelector}"
                         IsOptionElementsEnabled="{Binding ElementName=ComparisonToggle, Path=IsChecked}">

    Edit: using v.2011.1.419.1040 (the latest version that I have access to)

    Best regards
  2. Answer
    Tobias Rodewi
    Tobias Rodewi avatar
    24 posts
    Member since:
    Apr 2010

    Posted 04 Aug 2011 Link to this post

    Adding the TemplateSelector and the templates as well just in case..

    <DataTemplate x:Key="DividerTemplate"
                  telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
        <Line StrokeThickness="1"
              X2="{Binding ActualWidth, ElementName=treeView, Mode=OneWay}"
              StrokeDashArray="4 2"
              Opacity="0.8" />
    <telerik:HierarchicalDataTemplate x:Key="TVITemplate"
                                      telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
                                      ItemsSource="{Binding Children}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Header}" />
            <Button Margin="5,0,0,0"
                    Visibility="{Binding Converter={StaticResource TreeViewItemToEditableConverter}}"
                    cal:Click.Command="{Binding DataContext.EditButtonClickedCommand, ElementName=rootGrid}"
                <Image x:Name="Edit"
                       Source="/ESP.Infrastructure;Component/Resources/Images/edit.png" />

    <Model:TemplateSelector x:Key="TemplateSelector"
                            DividerTemplate="{StaticResource DividerTemplate}"
                            TVITemplate="{StaticResource TVITemplate}" />

    public class TemplateSelector : DataTemplateSelector
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
            if (item is TVIWrapper && (item as TVIWrapper).Type == Enumerators.TVIType.Divider)
                return DividerTemplate;
            if (item is TVIWrapper)
                return TVITemplate;
            return null;
        public DataTemplate DividerTemplate { get; set; }
        public DataTemplate TVITemplate { get; set; }
  3. DevCraft banner
  4. Tobias Rodewi
    Tobias Rodewi avatar
    24 posts
    Member since:
    Apr 2010

    Posted 04 Aug 2011 Link to this post

  5. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 09 Aug 2011 Link to this post

    Hi Tobias Lolax,

    Thank you for reporting this issue. It seems that the synchronization between the TreeView.IsOptionElementsEnabled with the TreeViewItem.OptionType properties needs to be improved in order to allow scenarios like yours.  I logged an item in our PITS where you can track its progress. In the meantime I attached a sample project illustrating another approach towards this scenario that you can use as a workaround for now.

    I also updated your Telerik points for bringing the issue to our attention.

    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top