/// <summary> /// Called when a MenuItem is clicked and raises a Click event. /// </summary> protected virtual void OnClick() { ContextMenu contextMenu = ParentMenuBase as ContextMenu; if (null != contextMenu) { contextMenu.ChildMenuItemClicked(); } // Wrapping the remaining code in a call to Dispatcher.BeginInvoke provides // WPF-compatibility by allowing the ContextMenu to close before the command // executes. However, it breaks the Clipboard.SetText scenario because the // call to SetText is no longer in direct response to user input. RoutedEventHandler handler = Click; if (null != handler) { handler(this, new RoutedEventArgs()); } if ((null != Command) && Command.CanExecute(CommandParameter)) { Command.Execute(CommandParameter); } }