Binding double click to tree item

5 posts, 0 answers
  1. David
    David avatar
    5 posts
    Member since:
    Jun 2013

    Posted 11 Jun 2013 Link to this post

    Hi

    I'm in the process of moving from the WPF TreeView to RadTreeView. I noticed I lost some capability with mouse double click when I changed it over to RadTreeView

    <telerik:RadTreeView x:Name="DeviceTreeView" Margin="2" VerticalContentAlignment="Top" ItemsSource="{Binding Recievers}" IsExpandOnDblClickEnabled="False">
     
                           <telerik:RadTreeView.Resources>
                               <HierarchicalDataTemplate
                                   DataType="{x:Type ViewModel:RecieverViewModel}"
                                   ItemsSource="{Binding Children}"
                                     >
                                   <StackPanel Orientation="Horizontal" >
                                       <!-- <Image Width="16" Height="16" Margin="3,0" Source="Images\Region.png" /> -->
                                       <TextBlock Text="{Binding Id}">
                                           <TextBlock.InputBindings>
                                               <MouseBinding Gesture="LeftDoubleClick" Command="{Binding Path=DataContext.OpenRecieverVisTabCommand, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}}" CommandParameter="{Binding Id}"/>
                                           </TextBlock.InputBindings>
                                       </TextBlock>
                                   </StackPanel>
                               </HierarchicalDataTemplate>
     
                               <HierarchicalDataTemplate
                                   DataType="{x:Type ViewModel:TripodViewModel}"
                                   ItemsSource="{Binding Children}"
                                     >
                                   <StackPanel Orientation="Horizontal" >
                                       <!-- <Image Width="16" Height="16" Margin="3,0" Source="Images\State.png" /> -->
                                       <TextBlock Text="{Binding Id}">
                                           <TextBlock.InputBindings>
                                               <MouseBinding Gesture="LeftDoubleClick" Command="{Binding Path=DataContext.OpenTripodVisTabCommand, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}}" CommandParameter="{Binding Id}"/>
                                           </TextBlock.InputBindings>
                                       </TextBlock>
                                   </StackPanel>
                               </HierarchicalDataTemplate>
     
                           </telerik:RadTreeView.Resources>
     
                           <telerik:RadTreeView.ItemContainerStyle>
                               <!--
                               This Style binds a TreeViewItem to a TreeViewItemViewModel.
                               -->
                               <Style TargetType="{x:Type telerik:RadTreeViewItem}">
                                   <Setter Property="IsExpanded" Value="true" />
                                   <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                                   <Setter Property="FontWeight" Value="Normal" />
                                   <Style.Triggers>
                                       <Trigger Property="IsSelected" Value="True">
                                           <Setter Property="FontWeight" Value="Bold" />
                                       </Trigger>
                                   </Style.Triggers>
                               </Style>
                           </telerik:RadTreeView.ItemContainerStyle>
     
                       </telerik:RadTreeView>

    Basically, I'm binding the tree items to a double click to a command. It's not workign in RadTreeView, Any ideas?

    Thanks, Dave
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 13 Jun 2013 Link to this post

    Hello David,

    In the Command bindings you're looking for a TreeView type. Please update your definition to look for x:Type telerik:RadTreeView and the code should work as expected.
    <MouseBinding Gesture="LeftDoubleClick" Command="{Binding Path=DataContext.OpenTripodVisTabCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadTreeView}}}" CommandParameter="{Binding Id}"/>

    Let us know if you encounter any other issues.

    Regards,
    Tina Stancheva
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Daniele
    Daniele avatar
    5 posts
    Member since:
    Apr 2016

    Posted 04 May Link to this post

    Good morning,

    I have about thesame problem butyour solution seems doesn not work...

    Here my code:

    <telerik:RadTreeView.Resources>

       <HierarchicalDataTemplate DataType="{x:Type trees:LibrariesNodeModel}" ItemsSource="{Binding Children}">

          <Grid>
             <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu>
                   <telerik:RadMenuItem Header="Import Library" Command="{Binding Path=DataContext.ImportLibraryCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadTreeView}}}" />

                </telerik:RadContextMenu>
             </telerik:RadContextMenu.ContextMenu>
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Border Background="{StaticResource LibrariesBrush}" Width="18" Height="18"/>
            <TextBlock Grid.Column="1" Text="{Binding Name}" Margin="3,0" />
         </Grid>

       </HierarchicalDataTemplate>

    </telerik:RadTreeView.Resources>

     

    Any suggestion?

    Regards

  5. Dinko
    Admin
    Dinko avatar
    202 posts

    Posted 05 May Link to this post

    Hello Daniele,

    In order to bind RadContextMenuItem to an ICommand property from your view model, you can bind the Tag property of the control which wraps the RadContextMenu control to the parent data context (in your case RadTreeView). Then you can bind the Command property of the RadMenuItem to the Tag property.
    <HierarchicalDataTemplate ItemsSource="{Binding Children}" >
        <Grid x:Name="wrapGrid" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadTreeView}}, Path=DataContext}">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu>
                    <telerik:RadMenuItem Header="Import Library"
                             Command="{Binding RelativeSource={RelativeSource Self},Path=Menu.UIElement.Tag.YourCommandName}" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
     
            <Border Background="{StaticResource LibrariesBrush}" Width="18" Height="18"/>
            <TextBlock Grid.Column="1" Text="{Binding Name}" Margin="3,0" />
        </Grid>
    </HierarchicalDataTemplate>

    Give this project a try and let us know if this works for you.

    Regards,
    Dinko
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Daniele
    Daniele avatar
    5 posts
    Member since:
    Apr 2016

    Posted 06 May Link to this post

    Good morning Dinko and thank you for your support!

    Your solution works correctly.

     

    Kind Regards

    Daniele

Back to Top
UI for WPF is Visual Studio 2017 Ready