DoubleClick in MVVM DataBound TreeView

2 posts, 0 answers
  1. Ashley
    Ashley avatar
    5 posts
    Member since:
    Mar 2015

    Posted 30 Mar 2015 Link to this post

    Hi guys

    I have toyed all morning with this problem. I have a DataBound RadTreeView (with ItemsSource) that displays a Hierarchical data structure.

    Because each item is displayed using the hierarchy I have no way of hooking into the "DoubleClick" event on a per-item basis.

    After some time, I ended up binding SelectedItem to my ViewModel and hooking into the ItemDoubleClick event like below. Unfortunately this makes the assumption that SelectedItem is fired before ItemDoubleClick. So if possible I would love to know a way to hook into the DoubleClick event, so that I can bind the CommandParameter to the item that was double clicked.

    <telerik:RadTreeView x:Name="ServerExplorerTreeView" Grid.Row="1" Margin="0 -2 0 0"
    VerticalAlignment="Stretch" Background="{StaticResource LightGrayBackgroundBrush}"
    IsLineEnabled="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" IsVirtualizing="True"
    SelectionMode="Multiple" IsEditable="True" IsDragDropEnabled="True" ItemsSource="{Binding NavigatorVM.Root.ItemsView.View}"
    SelectedItem="{Binding NavigatorVM.SelectedItem,Mode=TwoWay}">
    <i:EventTrigger EventName="ItemDoubleClick">
    <i:InvokeCommandAction Command="{Binding NavigatorVM.ItemDoubleClickedCommand}"/>

  2. Martin
    Martin avatar
    1041 posts

    Posted 01 Apr 2015 Link to this post

    Hello Ashley,

    You can use our EventToCommandBehavior to attach your command to the ItemDoubleClick event and pass the arguments of the event to the command parameters. This way you will be able to get the double clicked item and modify it as desired.
    public class MyViewModel
        public DelegateCommand ItemDoubleClickedCommand { get; set; }
        public MyViewModel()
            this.ItemDoubleClickedCommand = new DelegateCommand(ExecuteItemDoubleClick);
        private void ExecuteItemDoubleClick(object obj)
            var clickedItem = obj as MyDataItem;
            // execute your logic

    <telerik:RadTreeView Name="tree">
            <telerik:EventBinding EventName="ItemDoubleClick" Command="{Binding ItemDoubleClickedCommand}" CommandParameter="{Binding ElementName=tree, Path=SelectedValue}" />
    However, keep in mind that the teeview's selection will be changed on the first click of the item. On the second click the item will be already selected. If the event to command behavior doesn't work for you, can you tell me what you want to achieve? This will allow me to think of an approach that could be suitable for your scenario and guide your further.

    Thank you for any help you can provide.


    See What's Next in App Development. Register for TelerikNEXT.

  3. DevCraft R3 2016 release webinar banner
Back to Top