Prevent Child Inheritence of a parents RadContextMenu

5 posts, 1 answers
  1. TheLostLeaf
    TheLostLeaf avatar
    34 posts
    Member since:
    Feb 2007

    Posted 25 Jan 2010 Link to this post

     

    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
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 26 Jan 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. TheLostLeaf
    TheLostLeaf avatar
    34 posts
    Member since:
    Feb 2007

    Posted 26 Jan 2010 Link to this post

    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 -------------------------------------------------------------------------------
  5. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 27 Jan 2010 Link to this post

    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.
  6. TheLostLeaf
    TheLostLeaf avatar
    34 posts
    Member since:
    Feb 2007

    Posted 27 Jan 2010 Link to this post

    Got it. Thanks.
Back to Top
UI for WPF is Visual Studio 2017 Ready