Prevent nodes from being selected

2 posts, 0 answers
  1. steven
    steven avatar
    2 posts
    Member since:
    Jul 2011

    Posted 06 Mar 2015 Link to this post

    I have a RadTreeView bound in an MVVM style application. If a selection does not contain Details I need to disable the ability to click on that node and keep the currently selected node highlighted. The user should still able to expand and collapse.

    I have tried to bind to PreviewSelected but the SelectedItem property still gets hit even if I switch e.handled = true and I lose the node highlighting on the currently selected node. 

    <
    UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="PHToCItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}" BasedOn="{StaticResource RadTreeViewDefaultItemPlusMinusStyle}">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
            </Style>
            <DataTemplate x:Key="Measure">
                <TextBlock Text="{Binding Name }" Style="{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}" VerticalAlignment="Center"/>
            </DataTemplate>
            <HierarchicalDataTemplate x:Key="Condition" ItemTemplate="{StaticResource Measure}" ItemsSource="{Binding Measures}">
                <TextBlock Text="{Binding Name}" Style="{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}" />
            </HierarchicalDataTemplate>
            <HierarchicalDataTemplate x:Key="ConditionGroup" ItemTemplate="{StaticResource Condition}" ItemsSource="{Binding Conditions}" >
                <TextBlock Text="{Binding Name }" FontWeight="Bold" Style="{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}" />
            </HierarchicalDataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
     
    ...
     
    <telerik:RadTreeView
        x:Name="RadTree"     
        telerik:TextSearch.TextPath="Name"   
        VirtualizingStackPanel.IsVirtualizing="True"
        VirtualizingStackPanel.VirtualizationMode="Recycling"
        ItemsSource="{Binding ResultObject}"
        Style="{StaticResource RadTreeViewDefaultPlusMinusStyle}"
        ExpanderStyle="{StaticResource RadTreeViewDefaultPlusMinusExpanderStyle}"
        ItemTemplate="{StaticResource ConditionGroup}"
        ItemContainerStyle="{StaticResource PHToCItemContainerStyle}"
        SelectedItem="{Binding ResultObject.SelectedIndexItem}" />

    dll version = 2014.1.331.45
  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 11 Mar 2015 Link to this post

    Hello Steven,

    Indeed, when you try the cancel the selection in the PreviewSelection event the previously selection is removed. However, this is not reproducible with the latest version of our controls. Furthermore, we recommend using the PreviewSelectionChanged event instead of the PreviewSelection. If you handle the PreviewSelectionChanged event of the tree, the issue won't be observed.
    private void RadTreeView_PreviewSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        e.Handled = true;
    }

    I hope this helps.

    Regards,
    Martin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top