WPF Telerik RadTreeView Select Node on right click

In an application that we are working on, we want to select the Telerik RadTreeViewItem node the user is right clicking on and display context menu for the selected node.

This is not supported out of the box by Telerik, so I wrote an attached property to accomplish this. Please take a look at the code snippet below.

Full Visual Studio 2010 solution is also uploaded on my google drive here.

<Window x:Class="RadTreeViewExtensions.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:RadTreeViewExtensions="clr-namespace:RadTreeViewExtensions"
        Title="Telerik RadTreeView Behavior: Select Node on right click " 
        Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <HierarchicalDataTemplate x:Key="ChildrenTemplate" ItemsSource="{Binding Path=Children}">
                <StackPanel>
                    <TextBlock Text="{Binding Name}" />
                </StackPanel>
            </HierarchicalDataTemplate>
        </Grid.Resources>
        <Telerik:RadTreeView ItemsSource="{Binding Items}" 
                             ItemTemplate="{StaticResource ChildrenTemplate}"
                             SelectionMode="Single" 
                             RadTreeViewExtensions:RadTreeViewBehavior.RightClickSelectsNode="True"/>
    </Grid>
</Window>


Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?