Dim logText As TextBox ... Dim menuTool As New MenuTool() menuTool.Caption = "Menu Tool" menuTool.ButtonType = MenuToolButtonType.SegmentedState menuTool.SmallImage = getImageSource("/Images/icons/Ribbon/QuickStyles_16x16.png") menuTool.LargeImage = getImageSource("/Images/icons/Ribbon/QuickStyles_32x32.png") menuTool.KeyTipForSegmentedButton = "MT" menuTool.ShouldDisplayGalleryPreview = True menuTool.Items.Add("Menu Item 1") menuTool.Items.Add("Menu Item 2") Dim OpenCmdBinding As New CommandBinding(ApplicationCommands.Open, OpenCmdExecuted, OpenCmdCanExecute) Me.logText.CommandBindings.Add(OpenCmdBinding) menuTool.Command = ApplicationCommands.Open menuTool.CommandTarget = Me.logText menuTool.CommandParameter = "Command parameter..." ' Execute Private Sub OpenCmdExecuted(ByVal target As Object, ByVal e As ExecutedRoutedEventArgs) Dim command As String, targetobj As String command = DirectCast(e.Command, RoutedCommand).Name targetobj = DirectCast(target, FrameworkElement).Name Debug.Write("The " + command + " command has been invoked on target object: " + targetobj + ". Parameter: " + e.Parameter) End Sub ' Can execute Private Sub OpenCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs) e.CanExecute = True End Sub
TextBox logText; ... MenuTool menuTool = new MenuTool(); menuTool.Caption = "Menu Tool"; menuTool.ButtonType = MenuToolButtonType.SegmentedState; menuTool.SmallImage= getImageSource("/Images/icons/Ribbon/QuickStyles_16x16.png"); menuTool.LargeImage= getImageSource("/Images/icons/Ribbon/QuickStyles_32x32.png"); menuTool.KeyTipForSegmentedButton="MT"; menuTool.ShouldDisplayGalleryPreview = true; menuTool.Items.Add("Menu Item 1"); menuTool.Items.Add("Menu Item 2"); CommandBinding OpenCmdBinding = new CommandBinding( ApplicationCommands.Open, OpenCmdExecuted, OpenCmdCanExecute); this.logText.CommandBindings.Add(OpenCmdBinding); menuTool.Command = ApplicationCommands.Open;//ApplicationCommands.Open; menuTool.CommandTarget = this.logText; menuTool.CommandParameter = "Command parameter..."; // Execute void OpenCmdExecuted(object target, ExecutedRoutedEventArgs e) { string command, targetobj; command = ((RoutedCommand)e.Command).Name; targetobj = ((FrameworkElement)target).Name; Debug.Write("The " + command + " command has been invoked on target object: " + targetobj + ". Parameter: " + e.Parameter); } // Can execute void OpenCmdCanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; }