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

Toggling IsOptionElementsEnabled messes with OptionType

3 Answers 98 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tobias Rodewi
Top achievements
Rank 1
Tobias Rodewi asked on 04 Aug 2011, 07:54 AM
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)?

ContainerBindings
<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}" />
</telerik:ContainerBindingCollection>

Converter
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;
                default:
                    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"
                         Background="Transparent"
                         BorderThickness="0"
                         Height="16"
                         Width="16"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center">
    <Image Source="/XXX.Infrastructure;Component/Resources/Images/scale.png" />
</telerik:RadToggleButton>
.....
<telerik:RadTreeView x:Name="treeView"
                     IsEnabled="{Binding CurrentlyFetchingData, Converter={StaticResource BooleanReverseConverter}}"
                     VerticalAlignment="Stretch"
                     HorizontalAlignment="Stretch"
                     ExpanderStyle="{StaticResource ExpanderStyle}"
                     ItemsSource="{Binding TreeViewItems, Mode=OneWay}"
                     SelectedItem="{Binding SelectedTVI, Mode=TwoWay}"
                     ItemTemplateSelector="{StaticResource TemplateSelector}"
                     IsOptionElementsEnabled="{Binding ElementName=ComparisonToggle, Path=IsChecked}">
                     .....
</telerik:RadTreeView>


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

Best regards
Tobias

3 Answers, 1 is accepted

Sort by
0
Accepted
Tobias Rodewi
Top achievements
Rank 1
answered on 04 Aug 2011, 08:24 AM
Adding the TemplateSelector and the templates as well just in case..

Template
<DataTemplate x:Key="DividerTemplate"
              telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
    <Line StrokeThickness="1"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Bottom"
          Margin="-20,0,0,0"
          X2="{Binding ActualWidth, ElementName=treeView, Mode=OneWay}"
          Stretch="Fill"
          Stroke="Gray"
          StrokeDashArray="4 2"
          Opacity="0.8" />
</DataTemplate>
<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"
                Background="Transparent"
                BorderThickness="0"
                Height="16"
                Width="16"
                Visibility="{Binding Converter={StaticResource TreeViewItemToEditableConverter}}"
                cal:Click.Command="{Binding DataContext.EditButtonClickedCommand, ElementName=rootGrid}"
                cal:Click.CommandParameter="{Binding}">
            <Image x:Name="Edit"
                   Source="/ESP.Infrastructure;Component/Resources/Images/edit.png" />
        </Button>
    </StackPanel>
</telerik:HierarchicalDataTemplate>

TemplateSelector
<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; }
}
0
Tobias Rodewi
Top achievements
Rank 1
answered on 04 Aug 2011, 08:52 AM
--
0
Tina Stancheva
Telerik team
answered on 09 Aug 2011, 03:22 PM
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.

Regards,
Tina Stancheva
the Telerik team

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

Tags
TreeView
Asked by
Tobias Rodewi
Top achievements
Rank 1
Answers by
Tobias Rodewi
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or