
Hi,
We are creating a context menu dynamically where we are trying to set its ".Command" property to execute custom operation on click of particular menu item of context menu.
But when context menu is populated, the menu items sets with ".Command" property are displays as "disabled".
Following is the code sample:Now when we run this code, it shows the context menu but with disabled "CustomOperation" menu item. If we comment the line where we are setting the ".Command" property then that menu item is enabled.
We are not understanding where we are making mistake?
Please share the sample code, it will be helpful.
Thanks,
Aurodh
[Modified at 04/12/2009 01:59 AM]
We are creating a context menu dynamically where we are trying to set its ".Command" property to execute custom operation on click of particular menu item of context menu.
But when context menu is populated, the menu items sets with ".Command" property are displays as "disabled".
Following is the code sample:
RibbonControls.ContextMenu mContextMenu = new RibbonControls.ContextMenu();
RibbonControls.Button objBtn = new RibbonControls.Button();
objBtn.Name = "btnCustom";
objBtn.Label = "CustomOperation";
objBtn.ScreenTipHeader = "Custom operation";
objBtn.Command = CustomCommands.cmdCustOperation;
mContextMenu.Items.Add(objBtn);
//Code for executing the command
public class CustomCommands
{
public static RoutedCommand cmdCustOperation = new RoutedCommand();
App.mMainWindow.CommandBindings.Add(new CommandBinding(CustomCommands.cmdCustOperation , cmdCustOperation_Executed,cmdCustOperation_CanExecute));
private void cmdCustOperation_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
e.Handled = true;
}
private void cmdCustOperation_Executed(object sender, ExecutedRoutedEventArgs e)
{
//Custom operation
}
}
We are not understanding where we are making mistake?
Please share the sample code, it will be helpful.
Thanks,
Aurodh
[Modified at 04/12/2009 01:59 AM]