ContextMenu in ItemTemplate

3 posts, 1 answers
  1. Ignazio
    Ignazio avatar
    2 posts
    Member since:
    Jul 2019

    Posted 09 Jul 2019 Link to this post

    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. Answer
    Dinko avatar
    985 posts

    Posted 12 Jul 2019 Link to this post

    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.
  3. Ignazio
    Ignazio avatar
    2 posts
    Member since:
    Jul 2019

    Posted 15 Jul 2019 in reply to Dinko Link to this post

    Thank you, it works.
Back to Top