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

ContextMenu in ItemTemplate

2 Answers 477 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Ignazio
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>
                                         Name="ResultSetReportTreeView"<br>
                                         IsVirtualizing="True" <br>
                                         ItemDoubleClick="RadTreeViewItemDoubleClick"<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>
                        </Style><br>
                    </telerik:RadTreeView.Resources><br>
                    <telerik:RadTreeView.ItemTemplate><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>
                                <StackPanel.ContextMenu><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
                                      </MenuItem><br>
                                    </ContextMenu><br>
                                </StackPanel.ContextMenu><br>
                            </StackPanel><br>
 <!--End of my Context menu--><br>
                        </HierarchicalDataTemplate><br>
                    </telerik:RadTreeView.ItemTemplate><br>
                </telerik:RadTreeView><br>
            </Grid><br>
        </telerik:RadExpander><br></p>

 

2 Answers, 1 is accepted

Sort by
0
Accepted
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. 

Regards,
Dinko
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.
0
Ignazio
Top achievements
Rank 1
answered on 15 Jul 2019, 02:14 PM
Thank you, it works.
Tags
ContextMenu
Asked by
Ignazio
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Ignazio
Top achievements
Rank 1
Share this question
or