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

Context Menu Content Builder Table Commands Not Showing

4 Answers 206 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Julie Jaegers
Top achievements
Rank 1
Julie Jaegers asked on 25 Feb 2011, 08:05 PM
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!


4 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 01 Mar 2011, 05:43 PM
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!
0
Stacey Haslag
Top achievements
Rank 1
answered on 01 Mar 2011, 08:11 PM
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;
}

0
Accepted
Iva Toteva
Telerik team
answered on 04 Mar 2011, 10:17 AM
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!
0
Julie Jaegers
Top achievements
Rank 1
answered on 04 Mar 2011, 02:38 PM
Thanks! This worked!
Tags
RichTextBox
Asked by
Julie Jaegers
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Stacey Haslag
Top achievements
Rank 1
Julie Jaegers
Top achievements
Rank 1
Share this question
or