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

Binding double click to tree item

4 Answers 199 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 12 Jun 2013, 03:42 AM
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

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 13 Jun 2013, 03:17 PM
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.

0
Daniele
Top achievements
Rank 1
answered on 04 May 2016, 09:09 AM

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

0
Dinko | Tech Support Engineer
Telerik team
answered on 05 May 2016, 01:51 PM
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.
0
Daniele
Top achievements
Rank 1
answered on 06 May 2016, 06:38 AM

Good morning Dinko and thank you for your support!

Your solution works correctly.

 

Kind Regards

Daniele

Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Daniele
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or