Context Menu Content Builder Table Commands Not Showing

5 posts, 1 answers
  1. Julie Jaegers
    Julie Jaegers avatar
    12 posts
    Member since:
    Oct 2009

    Posted 25 Feb 2011 Link to this post

    I cannot get the table builder options to show up in my popup menu. I have attached my xaml (xaml radrichtextbox.png) and my View Model code (viewmodelcode.png). I have also attached a screen shot of what my menu looks like (screen shot.png). I got this code from a thread on this Telerik forum so I'm not sure what I'm doing wrong. Any help? Thanks!


  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 01 Mar 2011 Link to this post

    Hi Julie Jaegers,

    The table options are only shown in the context menu when you right-click in a table. This is so, because the commands that they trigger need an instance of a table - it has to be clear which table you want to insert a row in, delete a row of, etc. The commands themselves cannot be executed, so even if you add them in the context menu, the context menu items will be disabled.
    If you decide to add other ContextMenuGroups to the context menu, you can do that by handling the Showing event of the context menu like this:

    (this.editor.ContextMenu as ContextMenu).Showing+=new EventHandler<ContextMenuEventArgs>(ContextMenu_Showing);
    void ContextMenu_Showing(object sender, ContextMenuEventArgs e)
    {
        e.ContextMenuGroupCollection.Add(CreateCustomMenuGroup());
    }
    I am not sure if this answers your question. Can you please elaborate a bit more on your scenario - we are also curious, do you use custom context menu because the built-in does not offer some functionality you need?

    Best wishes,
    Iva
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Stacey Haslag
    Stacey Haslag avatar
    30 posts
    Member since:
    Oct 2009

    Posted 01 Mar 2011 Link to this post

    Hi, I am working with Julie to get this accomplished. Thanks for clarifying about the table commands, that makes sense, and the insert row, delete row, etc commands are working as desired.

    However, we would like to also have an Insert Table command available at all times when the user right-clicks. I have implemented your suggestions about listening to the context menu showing event, and adding a custom context menu group. This code does put an "Insert Table" menu option in my context menu; however, it does nothing.

    I would like to "steal" the built in RadRichTextBox.Commands.InsertTableCommand logic; and just put that into a context menu. Can I even do that?

    Thanks for your help!
    Stacey

    FYI: here is my code to add my custom menu group to the context menu; again, this is adding the insert table group successfully, but when clicked, does nothing:

    private void radRichTextBoxEdit_Loaded(object sender, RoutedEventArgs e)
    {
        RadEn_USDictionary radDict = new RadEn_USDictionary();
        ((DocumentSpellChecker)this.radRichTextBoxEdit.SpellChecker).AddDictionary(radDict, CultureInfo.InvariantCulture);
        ContextMenu contextMenu = (ContextMenu)this.radRichTextBoxEdit.ContextMenu;
        contextMenu.Showing += new System.EventHandler<ContextMenuEventArgs>(contextMenu_Showing);      
    }
    private void contextMenu_Showing(object sender, ContextMenuEventArgs e)
    {
        e.ContextMenuGroupCollection.Add(CreateCustomMenuGroup());
    }
    private ContextMenuGroup CreateCustomMenuGroup()
    {
        RadMenuItem item = new RadMenuItem();
        item.Header = "Insert Table";
        item.Command = this.radRichTextBoxEdit.Commands.InsertTableCommand;
        ContextMenuGroup group = new ContextMenuGroup();
        group.Add(item);
        return group;
    }

  4. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 04 Mar 2011 Link to this post

    Hi Stacey Haslag,

    The InsertTableCommand is not executed, because it requires a parameter indicating the number of rows and columns you want to have in the table. If you want to insert a table that has 3 rows and 2 columns for example, you need to set the CommandParameter property of the item like this:

    Copy Code
    item.CommandParameter = new InsertTableCommandParameter(3, 2);

    However, since there is no way to know how many rows and columns the user would like to have in the table, a better approach would be to use ShowInsertTableDialogCommand, that would show a dialog where you can set the initial row and column number. The only line you need to change is where you set the command:
    Copy Code
    item.Command = this.radRichTextBoxEdit.Commands.ShowInsertTableDialogCommand;

    If you have other questions, do not hesitate to contact us again.

    Kind regards,
    Iva
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. Julie Jaegers
    Julie Jaegers avatar
    12 posts
    Member since:
    Oct 2009

    Posted 04 Mar 2011 Link to this post

    Thanks! This worked!
Back to Top