MVVM binding double click to method using telerik radtreecontrol

2 posts, 0 answers
  1. Jessica
    Jessica avatar
    3 posts
    Member since:
    Jul 2012

    Posted 13 Dec 2012 Link to this post

    I am coding in WPF C# using MVVM design pattern. We try to adhere strictly to the pattern and put nothing in the code behind unless there is no option or it is completely unreasonable to do so. Having said that, I am working with a Telerik RadTreeView. Here is a snippet of it in my XAML:

    <telerik:RadTreeView IsExpandOnSingleClickEnabled="True" IsLineEnabled="True" Margin="5"
    ItemsSource="{Binding ItemsView}"
    SelectedItem="{Binding SelectedWidget, Mode=TwoWay}"
    ItemTemplate="{StaticResource NodeTemplate}" />

    Currently the tree is working properly so that if you highlight a tree item and click the OK button on the view, all is good. However, I need to also allow the user to double click on one of the tree items. This means I already have a command and method, protected override void OkAction(), in my view model with the needed logic. Telerik supplies a property called ItemDoubleClick that is supposed to supply functionality for the tree item double click. But I can't find anything to allow me to do this in the view model. In other words, how do I do the binding? We also have a behavior setup in our project for double clicking that I was told I could use, but I have no experience with behaviors. I'm still a little wet with WPF.


    I would appreciate any help or direction anyone can provide.

    XAML for NodeTemplate:

                <DataTemplate x:Key="WidgetTemplate">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Resources/gear1.png" Margin="1" Stretch="None" />
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="6,0,0,0" />
                <HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource = "{Binding Children}" ItemTemplate="{StaticResource WidgetTemplate}">
                    <TextBlock Text="{Binding Name}"/>
  2. Hristo
    Hristo avatar
    352 posts

    Posted 18 Dec 2012 Link to this post

    Hi Jessica,

    You could use the CommandExecutionTrigger and Command property of the TreeViewItem.

    If you set the CommandExecutionTrigger to DoubleClick the TreeViewItem command will be executed on double click. Also you could bind the RadTreeViewItem Command property to your custom view-model command in style setter.

    Hope this helps. Please let us know if you need more info or the suggested approach does not work for you.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top