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

Prevent Child Inheritence of a parents RadContextMenu

4 Answers 183 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
TheLostLeaf
Top achievements
Rank 2
TheLostLeaf asked on 26 Jan 2010, 01:22 AM
 

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

Sort by
0
Hristo
Telerik team
answered on 26 Jan 2010, 07:23 AM
Hi Eric,

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.
0
TheLostLeaf
Top achievements
Rank 2
answered on 26 Jan 2010, 06:40 PM
Here is a test project outlining the question. If you right click the child tree item you still get the main context menus, not the child context menu. (vs2010, Q3WPFsp2, C#) using RadContextMenu and ContextMenu together.
----------------------------- 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

      
    }
}

------------------------------------------------- end c# ---------------------------------------------------------------------------

---------------------------------------------------- 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 -------------------------------------------------------------------------------
0
Accepted
Hristo
Telerik team
answered on 27 Jan 2010, 07:39 AM
Hello TheLostLeaf,

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.
0
TheLostLeaf
Top achievements
Rank 2
answered on 27 Jan 2010, 06:43 PM
Got it. Thanks.
Tags
ContextMenu
Asked by
TheLostLeaf
Top achievements
Rank 2
Answers by
Hristo
Telerik team
TheLostLeaf
Top achievements
Rank 2
Share this question
or