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

MVVM binding double click to method using telerik radtreecontrol

1 Answer 117 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jessica
Top achievements
Rank 2
Jessica asked on 13 Dec 2012, 08:48 PM
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:

<Grid.Resources>
            <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" />
                </StackPanel>
            </DataTemplate>

            <HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource = "{Binding Children}" ItemTemplate="{StaticResource WidgetTemplate}">
                <TextBlock Text="{Binding Name}"/>
            </HierarchicalDataTemplate>

        </Grid.Resources>

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 18 Dec 2012, 12:17 PM
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,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeView
Asked by
Jessica
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Share this question
or