Adding to Context menu problem with multiple RichTextBox instances

3 posts, 1 answers
  1. Ralph
    Ralph avatar
    9 posts
    Member since:
    Feb 2014

    Posted 22 May 2014 Link to this post

    Our WPF application contains multiple RadRichTextBox instances. When right clicking in one of the instances I expected the ContextMenu_Showing event to get fired for only the RadRichTextBox control that I right clicked. This is not the case. 

    The method gets fired for each instance of the RadRichTextBox.  As a result, instead of getting one "View Source" context menu item inserted into the context menu, I get one for each RadRichTextBox control.

    I am trying to implement the modification of the RadRichTextBox's context menu as indicated at the following link:

    I also modified the example as indicated in the following blog to reference the correct ContextMenu:

    In the Telerik public constructor I have the following code:

                Telerik.Windows.Controls.RichTextBoxUI.ContextMenu contextMenu =
                contextMenu.Showing += this.ContextMenu_Showing;

    I also have the following methods:

            private void ContextMenu_Showing(object sender, Telerik.Windows.Controls.RichTextBoxUI.Menus.ContextMenuEventArgs e)
                RadMenuItem makeViewSourceMenuItem = new RadMenuItem()
                    Header = "View Source"
                makeViewSourceMenuItem.Click += MakeViewSourceMenuItem_Click;
                ContextMenuGroup customContextMenuGroup = new ContextMenuGroup();
            }        private void MakeViewSourceMenuItem_Click(object sender, RadRoutedEventArgs e)
                FrmHtmlSource dialog = new FrmHtmlSource(_originalText);

    All the examples I have seen involve just one instance of the RadRichTextBox.  Is there anything special I need to do to support multiple instances or is this a limitation with the RadRichTextBox control.
  2. Answer
    Boby avatar
    631 posts

    Posted 26 May 2014 Link to this post

    Hi Ralph,
    This is known peculiarity of the RadRichTextBox, caused by the fact that ContextMenu is instantiated by MEF, which by default caches the instance for reuse - meaning that all RadRichTextBox instances use one and the same context menu.

    As a workaround, I would suggest you to try one of the two approaches explained in this forum thread.

    Don't hesitate to contact us if you have other questions.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. Ralph
    Ralph avatar
    9 posts
    Member since:
    Feb 2014

    Posted 27 May 2014 in reply to Boby Link to this post

    Thanks Boby,  you suggestion fixed the problem.
Back to Top