I Have a RadContextMenu in XAML in a RadTreeView that works fine. I dynamically load the tree items, and certain tree items I add a different Context menu, but it always opens the RadContextMenu in xaml. If I remove the xaml RadContextMenu ref, the dynamic ContextMenu loads.
So I guess is there a way to prevent every child from inheriting its parents context menu?
Thanks
4 Answers, 1 is accepted
I'm not sure that I understand your scenario. Could you send us small project demonstrating this issue?
As far as I know RadTreeViewItem do not inherit RadContextMenu from RadTreeView so the problem is something else.
Best wishes,
Hristo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
----------------------------- C# ---------------------------------------------------
using System.Windows;
using Telerik.Windows.Controls;
using System.Windows.Controls;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadTree();
}
#region //// Tree Helpers //////////////////////////////////
private void LoadTree()
{
for (int i = 0; i < 10; i++)
{
RadTreeViewItem rtvi = new RadTreeViewItem();
rtvi.Header = "Item " + i.ToString();
rtvi = GetChildren(rtvi);
radTreeView1.Items.Add(rtvi);
}
}
private ContextMenu GetChildMenu()
{
ContextMenu ctxm = new ContextMenu();
MenuItem mi = new MenuItem();
mi.Header = "Parent Context Menu";
ctxm.Items.Add(mi);
return ctxm;
}
private RadTreeViewItem GetChildren(RadTreeViewItem rtviParent)
{
for (int i = 0; i < children.Length; i++)
{
RadTreeViewItem rtvi = new RadTreeViewItem();
rtvi.Header = "Child " + i.ToString();
rtvi.ContextMenu = GetChildMenu();
rtviParent.Items.Add(rtvi);
}
return rtviParent;
}
#endregion
}
}
---------------------------------------------------- xaml --------------------------------------------------------------------------
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<WrapPanel>
<telerik:RadTreeView HorizontalAlignment="Left" Margin="5" Name="radTreeView1" VerticalAlignment="Top">
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu x:Name="radContextMenu">
<telerik:RadMenuItem Header="New Child" />
<telerik:RadMenuItem Header="New Sibling" />
<telerik:RadMenuItem IsSeparator="True" />
<telerik:RadMenuItem Header="Edit" />
<telerik:RadMenuItem Header="Delete" />
<telerik:RadMenuItem IsSeparator="True" />
<telerik:RadMenuItem Header="Select" />
</telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
</telerik:RadTreeView>
</WrapPanel>
</Window>
-------------------------------------------- end xaml -------------------------------------------------------------------------------
You are mixing Microsoft ContextMenu control and our RadContextMenu. In this case RadContextMenu will open before Microsoft ContextMenu.
There is no need to attach context menus on every RadTreeViewItem. RadContextMenu have GetClickedElement<T>() method which can be used to get the element on which was clicked.
You can see it here:
http://demos.telerik.com/wpf/?ContextMenu/WPF/FirstLook
Let us know if you need more information.
Regards,
Hristo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.