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

ContextMenu in ItemTemplate

2 Answers 254 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Ignazio asked on 09 Jul 2019, 11:14 AM

I am working on some legacy code, I have RadTreeView with Item template which expand the hierarchy at doubleclick, I want to add a contextmenu which expand the hierarchy in the same way, problem is that there is no command to bind to expand nodes. How can I have the context menu work in the same way as the itemtemplate?


<p></p><p>                <telerik:RadTreeView Grid.Row="2" Background="White" BorderBrush="DarkGray" BorderThickness="1" VerticalAlignment="Stretch"<br>
                                         IsVirtualizing="True" <br>
                                         Width="{Binding ElementName=GuideControl, Path=ActualWidth}"<br>                                         ItemContainerStyle="{StaticResource ResourceKey=HierarchyTreeViewStyle}"<br>                                         SelectedItem="{Binding Path=SelectedNode, Mode=TwoWay}"<br>
                                       ItemsSource="{Binding ResultSetReportNodes}"<br>
                                         SelectionMode="Single" ><br>
                    <br>                    <telerik:RadTreeView.Resources><br>
                        <Style TargetType="{x:Type telerik:RadTreeViewItem}"><br>
                            <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" /><br>
                        <HierarchicalDataTemplate ItemsSource="{Binding Path=Children}"><br>
                            <StackPanel Orientation="Horizontal" Background="Transparent" ToolTip="{Binding Path=Name, Mode=OneWay}"><br>
                                <Image Style="{StaticResource ResourceKey=IconStyle}" VerticalAlignment="Center" Margin="5,0,0,0"/><br>
                                <TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Name, Mode=OneWay}" Margin="5,0,0,0"/><br>
 <!--start of my Context menu--><br>
                                    <ContextMenu><br>                                        <!--ExpandAllDescendantFoldersCommand IsCheckable=" empty I need it to work as itemtemplate does at doubleclick"--><br>                                        <MenuItem Header="{localization:Resx ResxName=Palantir.CommonResources.ButtonLabels, Key=Expand}" Command="{Binding Path=PlacementTarget.Tag.ExpandAllDescendantFoldersCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Mode=OneWay}"><br
 <!--End of my Context menu--><br>


2 Answers, 1 is accepted

Sort by
Dinko | Tech Support Engineer
Telerik team
answered on 12 Jul 2019, 09:59 AM
Hello Ignazio,

Thank you for the provided code snippet. 

My current understanding is that you want to provide a context menu for the RadTreeViewItems and expand them when the menuitem is clicked.

If that is indeed the case, you can utilize the RadContextMenu control and the IsChecked property of the RadMenuItem. I am attaching a sample project demonstrating what I have in mind for your reference.

I hope you find this helpful. 

Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Top achievements
Rank 1
answered on 15 Jul 2019, 02:14 PM
Thank you, it works.
Asked by
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Top achievements
Rank 1
Share this question