コード例 #1
0
 public static void AddCommandPreviewCanExecuteHandler(this CommandBindingCollection collection, RoutedCommand command, CanExecuteRoutedEventHandler handler)
 {
     CommandBinding binding = GetOrCreateBinding(collection, command);
     // Remove the handler if it already exist
     binding.PreviewCanExecute -= handler;
     binding.PreviewCanExecute += handler;
 }
コード例 #2
0
ファイル: AsyncCommandBinding.cs プロジェクト: Mrding/Ribbon
        public AsyncCommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute, RunWorkerCompletedEventHandler runWokrerCompleted)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            _task = new BackgroundWorker();
            _task.DoWork += delegate
                                {
                                    executed(null, null);
                                };
            _task.RunWorkerCompleted += (s, e) =>
                                            {
                                                runWokrerCompleted(s, e);
                                                _task.Dispose();
                                            };

            Command = command;
            if (executed != null)
            {
                Executed += delegate
                                {
                                    if (!_task.IsBusy)
                                        _task.RunWorkerAsync();
                                };
            }
            if (canExecute != null)
            {
                CanExecute += canExecute;
            }
        }
コード例 #3
0
        //----------------------------------------------------- 
        //
        //  Class Internal Methods 
        // 
        //-----------------------------------------------------
 
        #region Class Internal Methods

        /// <summary>
        /// Registes all handlers needed for text editing control functioning. 
        /// </summary>
        /// <param name="controlType"> 
        /// A type of control for which typing component is registered 
        /// </param>
        /// <param name="registerEventListeners"> 
        /// If registerEventListeners is false, caller is responsible for calling OnXXXEvent methods on TextEditor from
        /// UIElement and FrameworkElement virtual overrides (piggy backing on the
        /// UIElement/FrameworkElement class listeners).  If true, TextEditor will register
        /// its own class listener for events it needs. 
        ///
        /// This method will always register private command listeners. 
        /// </param> 
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        { 
            if (registerEventListeners)
            {
                EventManager.RegisterClassHandler(controlType, Keyboard.PreviewKeyDownEvent, new KeyEventHandler(OnPreviewKeyDown));
                EventManager.RegisterClassHandler(controlType, Keyboard.KeyDownEvent, new KeyEventHandler(OnKeyDown)); 
                EventManager.RegisterClassHandler(controlType, Keyboard.KeyUpEvent, new KeyEventHandler(OnKeyUp));
                EventManager.RegisterClassHandler(controlType, TextCompositionManager.TextInputEvent, new TextCompositionEventHandler(OnTextInput)); 
            } 

            var onEnterBreak = new ExecutedRoutedEventHandler(OnEnterBreak); 
            var onSpace = new ExecutedRoutedEventHandler(OnSpace);
            var onQueryStatusNYI = new CanExecuteRoutedEventHandler(OnQueryStatusNYI);
            var onQueryStatusEnterBreak = new CanExecuteRoutedEventHandler(OnQueryStatusEnterBreak);
 
            EventManager.RegisterClassHandler(controlType, Mouse.MouseMoveEvent, new MouseEventHandler(OnMouseMove), true /* handledEventsToo */);
            EventManager.RegisterClassHandler(controlType, Mouse.MouseLeaveEvent, new MouseEventHandler(OnMouseLeave), true /* handledEventsToo */); 
 
            CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.CorrectionList   , new ExecutedRoutedEventHandler(OnCorrectionList)       , new CanExecuteRoutedEventHandler(OnQueryStatusCorrectionList)       , SRID.KeyCorrectionList,   SRID.KeyCorrectionListDisplayString         );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleInsert         , new ExecutedRoutedEventHandler(OnToggleInsert)         , onQueryStatusNYI                  , SRID.KeyToggleInsert,     SRID.KeyToggleInsertDisplayString           ); 
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.Delete               , new ExecutedRoutedEventHandler(OnDelete)               , onQueryStatusNYI                  , SRID.KeyDelete,           SRID.KeyDeleteDisplayString                 );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteNextWord       , new ExecutedRoutedEventHandler(OnDeleteNextWord)       , onQueryStatusNYI                  , SRID.KeyDeleteNextWord,   SRID.KeyDeleteNextWordDisplayString         );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeletePreviousWord   , new ExecutedRoutedEventHandler(OnDeletePreviousWord)   , onQueryStatusNYI                  , SRID.KeyDeletePreviousWord, SRID.KeyDeletePreviousWordDisplayString   );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.EnterParagraphBreak  , onEnterBreak                                           , onQueryStatusEnterBreak           , SRID.KeyEnterParagraphBreak, SRID.KeyEnterParagraphBreakDisplayString ); 
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.EnterLineBreak       , onEnterBreak                                           , onQueryStatusEnterBreak           , SRID.KeyEnterLineBreak,   SRID.KeyEnterLineBreakDisplayString         );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.TabForward           , new ExecutedRoutedEventHandler(OnTabForward)           , new CanExecuteRoutedEventHandler(OnQueryStatusTabForward)           , SRID.KeyTabForward,       SRID.KeyTabForwardDisplayString             ); 
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.TabBackward          , new ExecutedRoutedEventHandler(OnTabBackward)          , new CanExecuteRoutedEventHandler(OnQueryStatusTabBackward)          , SRID.KeyTabBackward,      SRID.KeyTabBackwardDisplayString            ); 
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.Space                , onSpace                                                , onQueryStatusNYI                  , SRID.KeySpace,            SRID.KeySpaceDisplayString                  );
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ShiftSpace           , onSpace                                                , onQueryStatusNYI                  , SRID.KeyShiftSpace,       SRID.KeyShiftSpaceDisplayString             ); 

            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.Backspace            , new ExecutedRoutedEventHandler(OnBackspace)            , onQueryStatusNYI                  , KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyBackspace),        SR.Get(SRID.KeyBackspaceDisplayString)),   KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyShiftBackspace), SR.Get(SRID.KeyShiftBackspaceDisplayString)) );

        } 
コード例 #4
0
ファイル: CommandHelpers.cs プロジェクト: sososu/wpf
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler,
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
                                             InputGesture inputGesture, InputGesture inputGesture2, InputGesture inputGesture3, InputGesture inputGesture4)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler,
                                   inputGesture, inputGesture2, inputGesture3, inputGesture4);
 }
コード例 #5
0
        private static void BindCommand(ICommand command, Action executed, CanExecuteRoutedEventHandler canExecute)
        {
            var binding = new CommandBinding(command, delegate { executed(); }, canExecute);

            CommandManager.RegisterClassCommandBinding(typeof(MainWindow), binding);
            CommandManager.RegisterClassCommandBinding(typeof(BookmarkWindow), binding);
        }
コード例 #6
0
ファイル: CommandEntry.cs プロジェクト: xydoublez/RDO.Net
 internal CommandEntry(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute, object inputGestures)
 {
     Command        = command;
     Executed       = executed;
     CanExecute     = canExecute;
     _inputGestures = inputGestures;
 }
コード例 #7
0
        public AsyncCommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute, RunWorkerCompletedEventHandler runWokrerCompleted)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            _task         = new BackgroundWorker();
            _task.DoWork += delegate
            {
                executed(null, null);
            };
            _task.RunWorkerCompleted += (s, e) =>
            {
                runWokrerCompleted(s, e);
                _task.Dispose();
            };

            Command = command;
            if (executed != null)
            {
                Executed += delegate
                {
                    if (!_task.IsBusy)
                    {
                        _task.RunWorkerAsync();
                    }
                };
            }
            if (canExecute != null)
            {
                CanExecute += canExecute;
            }
        }
コード例 #8
0
        //------------------------------------------------------
        //
        //  Class Internal Methods
        //
        //------------------------------------------------------

        #region Class Internal Methods

        // Registers all text editing command handlers for a given control type
        internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool readOnly, bool registerEventListeners)
        {
            CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Copy, new ExecutedRoutedEventHandler(OnCopy), new CanExecuteRoutedEventHandler(OnQueryStatusCopy), KeyGesture.CreateFromResourceStrings(KeyCopy, SR.Get(SRID.KeyCopyDisplayString)), KeyGesture.CreateFromResourceStrings(KeyCtrlInsert, SR.Get(SRID.KeyCtrlInsertDisplayString)));
            if (acceptsRichContent)
            {
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.CopyFormat, new ExecutedRoutedEventHandler(OnCopyFormat), new CanExecuteRoutedEventHandler(OnQueryStatusCopyFormat), KeyGesture.CreateFromResourceStrings(KeyCopyFormat, SRID.KeyCopyFormatDisplayString));
            }
            if (!readOnly)
            {
                CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Cut, new ExecutedRoutedEventHandler(OnCut), new CanExecuteRoutedEventHandler(OnQueryStatusCut), KeyGesture.CreateFromResourceStrings(KeyCut, SR.Get(SRID.KeyCutDisplayString)), KeyGesture.CreateFromResourceStrings(KeyShiftDelete, SR.Get(SRID.KeyShiftDeleteDisplayString)));
                // temp vars to reduce code under elevation
                ExecutedRoutedEventHandler   ExecutedRoutedEventHandler   = new ExecutedRoutedEventHandler(OnPaste);
                CanExecuteRoutedEventHandler CanExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(OnQueryStatusPaste);
                InputGesture inputGesture = KeyGesture.CreateFromResourceStrings(KeyShiftInsert, SR.Get(SRID.KeyShiftInsertDisplayString));
                new UIPermission(UIPermissionClipboard.AllClipboard).Assert(); //BlessedAssert
                try
                {
                    CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Paste, ExecutedRoutedEventHandler, CanExecuteRoutedEventHandler, inputGesture);
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
                if (acceptsRichContent)
                {
                    CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.PasteFormat, new ExecutedRoutedEventHandler(OnPasteFormat), new CanExecuteRoutedEventHandler(OnQueryStatusPasteFormat), KeyPasteFormat, SRID.KeyPasteFormatDisplayString);
                }
            }
        }
コード例 #9
0
        protected void RegisterAllCommandsViaReflections()
        {
            Type type = this.GetType();
            //--------------------
            const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
            List <MemberInfo>  members      = type.GetFields(bindingFlags)
                                              .Where(p => p.FieldType.Name.Contains("RoutedUICommand"))
                                              .Cast <MemberInfo>().ToList();
            //----------------------------
            Type commandType = typeof(RoutedUICommand);

            foreach (MemberInfo memInf  in members)
            {
                CommandBinding binding         = null;
                string         nameCommand     = memInf.Name.SubstringInside("<", ">");
                var            instanceCommand = (RoutedUICommand)Activator
                                                 .CreateInstance(commandType, new object[] { nameCommand, nameCommand, type });
                memInf.As <FieldInfo>().SetValue(this, instanceCommand);
                //-----------------------------------------------------
                string     mNameExecuted  = nameCommand + "Executed";
                MethodInfo methodInfoExec = type.GetMethod(mNameExecuted, bindingFlags);
                ExecutedRoutedEventHandler executedHandler = (a, e) => methodInfoExec.Invoke(a, new object[] { a, e });
                //------------------------------------------------------------------------------------
                string     mNameCanExecuted  = nameCommand + "CanExecuted";
                MethodInfo methodInfoCanExec = type.GetMethod(mNameCanExecuted, bindingFlags);
                CanExecuteRoutedEventHandler canExecuteHandler = null;
                if (methodInfoCanExec != null)
                {
                    canExecuteHandler = (a, e) => methodInfoCanExec.Invoke(a, new object[] { a, e });
                }
                //-------------------------------------------------------------------------------------
                binding = new CommandBinding(instanceCommand, executedHandler, canExecuteHandler);
                CommandManager.RegisterClassCommandBinding(typeof(MainWindow), binding);
            }
        }
コード例 #10
0
 public CommandModel(RoutedCommand command, ExecutedRoutedEventHandler executedHandler,
                     CanExecuteRoutedEventHandler canExecuteHandler)
 {
     this.command           = command;
     this.executedHandler   = executedHandler;
     this.canExecuteHandler = canExecuteHandler;
 }
コード例 #11
0
 public CommandModel(ExecutedRoutedEventHandler executedHandler,
                     CanExecuteRoutedEventHandler canExecuteHandler)
 {
     command = new RoutedCommand();
     this.executedHandler   = executedHandler;
     this.canExecuteHandler = canExecuteHandler;
 }
コード例 #12
0
 internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool readOnly, bool registerEventListeners)
 {
     CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Copy, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCopy), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCopy), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCopy"), SR.Get("KeyCopyDisplayString")), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCtrlInsert"), SR.Get("KeyCtrlInsertDisplayString")));
     if (acceptsRichContent)
     {
         CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.CopyFormat, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCopyFormat), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCopyFormat), "KeyCopyFormat", "KeyCopyFormatDisplayString");
     }
     if (!readOnly)
     {
         CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Cut, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnCut), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusCut), KeyGesture.CreateFromResourceStrings(SR.Get("KeyCut"), SR.Get("KeyCutDisplayString")), KeyGesture.CreateFromResourceStrings(SR.Get("KeyShiftDelete"), SR.Get("KeyShiftDeleteDisplayString")));
         ExecutedRoutedEventHandler   executedRoutedEventHandler   = new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnPaste);
         CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusPaste);
         InputGesture inputGesture = KeyGesture.CreateFromResourceStrings(SR.Get("KeyShiftInsert"), SR.Get("KeyShiftInsertDisplayString"));
         new UIPermission(UIPermissionClipboard.AllClipboard).Assert();
         try
         {
             CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Paste, executedRoutedEventHandler, canExecuteRoutedEventHandler, inputGesture);
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
         if (acceptsRichContent)
         {
             CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.PasteFormat, new ExecutedRoutedEventHandler(TextEditorCopyPaste.OnPasteFormat), new CanExecuteRoutedEventHandler(TextEditorCopyPaste.OnQueryStatusPasteFormat), "KeyPasteFormat", "KeyPasteFormatDisplayString");
         }
     }
 }
コード例 #13
0
ファイル: CommandHelpers.cs プロジェクト: sjyanxin/WPFSource
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, 
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
                                             InputGesture inputGesture, InputGesture inputGesture2, InputGesture inputGesture3, InputGesture inputGesture4) 
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler,
                                   inputGesture, inputGesture2, inputGesture3, inputGesture4);
 } 
コード例 #14
0
ファイル: CustomTitlebar.cs プロジェクト: yongaru/fuse-studio
        public static void ApplyTo(System.Windows.Window window)
        {
            CanExecuteRoutedEventHandler onCanResizeWindow = (sender, e) =>
            {
                e.CanExecute =
                    window.ResizeMode == ResizeMode.CanResize ||
                    window.ResizeMode == ResizeMode.CanResizeWithGrip;
            };

            CanExecuteRoutedEventHandler onCanMinimizeWindow = (sender, e) =>
            {
                e.CanExecute = window.ResizeMode != ResizeMode.NoResize;
            };

            ExecutedRoutedEventHandler onCloseWindow    = (sender, e) => SystemCommands.CloseWindow(window);
            ExecutedRoutedEventHandler onMaximizeWindow = (sender, e) =>
            {
                SystemCommands.MaximizeWindow(window);
            };
            ExecutedRoutedEventHandler onMinimizeWindow = (sender, e) => SystemCommands.MinimizeWindow(window);
            ExecutedRoutedEventHandler onRestoreWindow  = (sender, e) =>
            {
                SystemCommands.RestoreWindow(window);
            };

            window.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, onCloseWindow));
            window.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, onMaximizeWindow, onCanResizeWindow));
            window.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, onMinimizeWindow, onCanMinimizeWindow));
            window.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, onRestoreWindow, onCanResizeWindow));
        }
コード例 #15
0
 private static void RegisterCommand(
     ICommand command,
     ExecutedRoutedEventHandler executed,
     CanExecuteRoutedEventHandler canExecute)
 {
     CommandManager.RegisterClassCommandBinding(
         typeof(RadScheduler), new CommandBinding(command, executed, canExecute));
 }
コード例 #16
0
 public static void RemoveCommandPreviewCanExecuteHandler(this CommandBindingCollection collection, RoutedCommand command, CanExecuteRoutedEventHandler handler)
 {
     CommandBinding binding = GetBinding(collection, command);
     if (binding != null)
     {
         binding.PreviewCanExecute -= handler;
     }
 }
コード例 #17
0
        protected virtual void OnCanClearPlottedPlaces(CanExecuteRoutedEventArgs e)
        {
            CanExecuteRoutedEventHandler handler = CanClearPlottedPlaces;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #18
0
        internal static new void InvokeHandler(Delegate handler, IntPtr sender, IntPtr args)
        {
            CanExecuteRoutedEventHandler handler_ = (CanExecuteRoutedEventHandler)handler;

            if (handler_ != null)
            {
                handler_(Extend.GetProxy(sender, false), new CanExecuteRoutedEventArgs(args, false));
            }
        }
コード例 #19
0
 /// <summary>
 /// Регистрирует обработчик команды
 /// </summary>
 /// <param name="controlType">Тип контрола</param>
 /// <param name="command">Команда</param>
 /// <param name="executedRoutedEventHandler">Обработчик выполнения команды</param>
 /// <param name="canExecuteRoutedEventHandler">Обработчик проверки возможности выполнения команды</param>
 /// <param name="inputGesture">Горячая клавиша</param>
 public static void RegisterCommandHandler(
     Type controlType,
     RoutedCommand command,
     ExecutedRoutedEventHandler executedRoutedEventHandler,
     CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
     InputGesture inputGesture)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, new[] { inputGesture });
 }
コード例 #20
0
 /// <summary>
 /// Регистрирует обработчик команды
 /// </summary>
 /// <param name="controlType">Тип контрола</param>
 /// <param name="command">Команда</param>
 /// <param name="executedRoutedEventHandler">Обработчик выполнения команды</param>
 /// <param name="canExecuteRoutedEventHandler">Обработчик проверки возможности выполнения команды</param>
 /// <param name="key">Горячая клавиша</param>
 public static void RegisterCommandHandler(
     Type controlType,
     RoutedCommand command,
     ExecutedRoutedEventHandler executedRoutedEventHandler,
     CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
     Key key)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, new InputGesture[] { new KeyGesture(key) });
 }
コード例 #21
0
ファイル: AppCommands.cs プロジェクト: gee12/SPUtility
 public static void SetCommandBinding(CommandBindingCollection commandCollection, ICommand command, 
     ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute = null)
 {
     var binding = (canExecute == null)
         ? new CommandBinding(command, executed)
         : new CommandBinding(command, executed, canExecute);
     commandCollection.Remove(binding);
     commandCollection.Add(binding);
 }
コード例 #22
0
        public static void SetCommandBinding(CommandBindingCollection commandCollection, ICommand command,
                                             ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute = null)
        {
            var binding = (canExecute == null)
                ? new CommandBinding(command, executed)
                : new CommandBinding(command, executed, canExecute);

            commandCollection.Remove(binding);
            commandCollection.Add(binding);
        }
コード例 #23
0
        static MessageDialog()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageDialog), new FrameworkPropertyMetadata(typeof(MessageDialog)));
            var onExcuteCommand    = new ExecutedRoutedEventHandler(OnExcuteCommand);
            var onCanExcuteCommand = new CanExecuteRoutedEventHandler(OnCanExcuteCommand);

            CommandManager.RegisterClassCommandBinding(typeof(MessageDialog), new CommandBinding(MessageDialog.YesCommand, onExcuteCommand, onCanExcuteCommand));
            CommandManager.RegisterClassCommandBinding(typeof(MessageDialog), new CommandBinding(MessageDialog.NoCommand, onExcuteCommand, onCanExcuteCommand));
            CommandManager.RegisterClassCommandBinding(typeof(MessageDialog), new CommandBinding(MessageDialog.ClosedCommand, onExcuteCommand, onCanExcuteCommand));
        }
コード例 #24
0
ファイル: MaskedTextBox.cs プロジェクト: StevenThuriot/Nova
        private static CommandBinding CreateCommandBinding(RoutedUICommand routedUICommand)
        {
            CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = (sender, args) =>
            {
                args.CanExecute = false;
                args.Handled    = true;
            };

            return(new CommandBinding(routedUICommand, null, canExecuteRoutedEventHandler));
        }
コード例 #25
0
        /// <summary>
        /// Creates the input gesture.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="key">The key to listen to.</param>
        /// <param name="modifierKeys">The modifier keys to listen to.</param>
        /// <param name="execute">The command to execute.</param>
        /// <param name="canExecute">The command to check if the main command can execute.</param>
        public static void CreateInputGesture(this UIElement element, Key key, ModifierKeys modifierKeys, ExecutedRoutedEventHandler execute, CanExecuteRoutedEventHandler canExecute)
        {
            var command = new RoutedUICommand();
            var binding = new CommandBinding(command, execute, canExecute);

            var gesture = new KeyGesture(key, modifierKeys);
            var keyBinding = new KeyBinding(command, gesture);

            element.CommandBindings.Add(binding);
            element.InputBindings.Add(keyBinding);
        }
コード例 #26
0
ファイル: CommandManager.cs プロジェクト: stanasse/olive
 public static void AddPreviewCanExecuteHandler(UIElement element, CanExecuteRoutedEventHandler handler)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     element.AddHandler(PreviewCanExecuteEvent, handler);
 }
コード例 #27
0
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        {
            // Shared handlers used multiple times below.
            ExecutedRoutedEventHandler nyiCommandHandler = new ExecutedRoutedEventHandler(OnNYICommand);
            CanExecuteRoutedEventHandler queryStatusCaretNavigationHandler = new CanExecuteRoutedEventHandler(OnQueryStatusCaretNavigation);
            CanExecuteRoutedEventHandler queryStatusKeyboardSelectionHandler = new CanExecuteRoutedEventHandler(OnQueryStatusKeyboardSelection);
            
            // Standard Commands: Select All
            // -----------------------------
            CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.SelectAll, new ExecutedRoutedEventHandler(OnSelectAll), queryStatusKeyboardSelectionHandler, SRID.KeySelectAll, SRID.KeySelectAllDisplayString);

            // Editing Commands : Caret Navigation
            // -----------------------------------
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveRightByCharacter, new ExecutedRoutedEventHandler(OnMoveRightByCharacter), queryStatusCaretNavigationHandler, SRID.KeyMoveRightByCharacter, SRID.KeyMoveRightByCharacterDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveLeftByCharacter, new ExecutedRoutedEventHandler(OnMoveLeftByCharacter), queryStatusCaretNavigationHandler, SRID.KeyMoveLeftByCharacter, SRID.KeyMoveLeftByCharacterDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveRightByWord, new ExecutedRoutedEventHandler(OnMoveRightByWord), queryStatusCaretNavigationHandler, SRID.KeyMoveRightByWord, SRID.KeyMoveRightByWordDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveLeftByWord, new ExecutedRoutedEventHandler(OnMoveLeftByWord), queryStatusCaretNavigationHandler, SRID.KeyMoveLeftByWord, SRID.KeyMoveLeftByWordDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveDownByLine, new ExecutedRoutedEventHandler(OnMoveDownByLine), queryStatusCaretNavigationHandler, SRID.KeyMoveDownByLine, SRID.KeyMoveDownByLineDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveUpByLine, new ExecutedRoutedEventHandler(OnMoveUpByLine), queryStatusCaretNavigationHandler, SRID.KeyMoveUpByLine, SRID.KeyMoveUpByLineDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveDownByParagraph, new ExecutedRoutedEventHandler(OnMoveDownByParagraph), queryStatusCaretNavigationHandler, SRID.KeyMoveDownByParagraph, SRID.KeyMoveDownByParagraphDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveUpByParagraph, new ExecutedRoutedEventHandler(OnMoveUpByParagraph), queryStatusCaretNavigationHandler, SRID.KeyMoveUpByParagraph, SRID.KeyMoveUpByParagraphDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveDownByPage, new ExecutedRoutedEventHandler(OnMoveDownByPage), queryStatusCaretNavigationHandler, SRID.KeyMoveDownByPage, SRID.KeyMoveDownByPageDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveUpByPage, new ExecutedRoutedEventHandler(OnMoveUpByPage), queryStatusCaretNavigationHandler, SRID.KeyMoveUpByPage, SRID.KeyMoveUpByPageDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToLineStart, new ExecutedRoutedEventHandler(OnMoveToLineStart), queryStatusCaretNavigationHandler, SRID.KeyMoveToLineStart, SRID.KeyMoveToLineStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToLineEnd, new ExecutedRoutedEventHandler(OnMoveToLineEnd), queryStatusCaretNavigationHandler, SRID.KeyMoveToLineEnd, SRID.KeyMoveToLineEndDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToColumnStart, nyiCommandHandler, queryStatusCaretNavigationHandler, SRID.KeyMoveToColumnStart, SRID.KeyMoveToColumnStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToColumnEnd, nyiCommandHandler, queryStatusCaretNavigationHandler, SRID.KeyMoveToColumnEnd, SRID.KeyMoveToColumnEndDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToWindowTop, nyiCommandHandler, queryStatusCaretNavigationHandler, SRID.KeyMoveToWindowTop, SRID.KeyMoveToWindowTopDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToWindowBottom, nyiCommandHandler, queryStatusCaretNavigationHandler, SRID.KeyMoveToWindowBottom, SRID.KeyMoveToWindowBottomDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToDocumentStart, new ExecutedRoutedEventHandler(OnMoveToDocumentStart), queryStatusCaretNavigationHandler, SRID.KeyMoveToDocumentStart, SRID.KeyMoveToDocumentStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MoveToDocumentEnd, new ExecutedRoutedEventHandler(OnMoveToDocumentEnd), queryStatusCaretNavigationHandler, SRID.KeyMoveToDocumentEnd, SRID.KeyMoveToDocumentEndDisplayString);

            // Editing Commands: Selection Building
            // ------------------------------------
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectRightByCharacter, new ExecutedRoutedEventHandler(OnSelectRightByCharacter), queryStatusKeyboardSelectionHandler, SRID.KeySelectRightByCharacter, SRID.KeySelectRightByCharacterDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectLeftByCharacter, new ExecutedRoutedEventHandler(OnSelectLeftByCharacter), queryStatusKeyboardSelectionHandler, SRID.KeySelectLeftByCharacter, SRID.KeySelectLeftByCharacterDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectRightByWord, new ExecutedRoutedEventHandler(OnSelectRightByWord), queryStatusKeyboardSelectionHandler, SRID.KeySelectRightByWord, SRID.KeySelectRightByWordDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectLeftByWord, new ExecutedRoutedEventHandler(OnSelectLeftByWord), queryStatusKeyboardSelectionHandler, SRID.KeySelectLeftByWord, SRID.KeySelectLeftByWordDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectDownByLine, new ExecutedRoutedEventHandler(OnSelectDownByLine), queryStatusKeyboardSelectionHandler, SRID.KeySelectDownByLine, SRID.KeySelectDownByLineDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectUpByLine, new ExecutedRoutedEventHandler(OnSelectUpByLine), queryStatusKeyboardSelectionHandler, SRID.KeySelectUpByLine, SRID.KeySelectUpByLineDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectDownByParagraph, new ExecutedRoutedEventHandler(OnSelectDownByParagraph), queryStatusKeyboardSelectionHandler, SRID.KeySelectDownByParagraph, SRID.KeySelectDownByParagraphDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectUpByParagraph, new ExecutedRoutedEventHandler(OnSelectUpByParagraph), queryStatusKeyboardSelectionHandler, SRID.KeySelectUpByParagraph, SRID.KeySelectUpByParagraphDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectDownByPage, new ExecutedRoutedEventHandler(OnSelectDownByPage), queryStatusKeyboardSelectionHandler, SRID.KeySelectDownByPage, SRID.KeySelectDownByPageDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectUpByPage, new ExecutedRoutedEventHandler(OnSelectUpByPage), queryStatusKeyboardSelectionHandler, SRID.KeySelectUpByPage, SRID.KeySelectUpByPageDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToLineStart, new ExecutedRoutedEventHandler(OnSelectToLineStart), queryStatusKeyboardSelectionHandler, SRID.KeySelectToLineStart, SRID.KeySelectToLineStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToLineEnd, new ExecutedRoutedEventHandler(OnSelectToLineEnd), queryStatusKeyboardSelectionHandler, SRID.KeySelectToLineEnd, SRID.KeySelectToLineEndDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToColumnStart, nyiCommandHandler, queryStatusKeyboardSelectionHandler, SRID.KeySelectToColumnStart, SRID.KeySelectToColumnStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToColumnEnd, nyiCommandHandler, queryStatusKeyboardSelectionHandler, SRID.KeySelectToColumnEnd, SRID.KeySelectToColumnEndDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToWindowTop, nyiCommandHandler, queryStatusKeyboardSelectionHandler, SRID.KeySelectToWindowTop, SRID.KeySelectToWindowTopDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToWindowBottom, nyiCommandHandler, queryStatusKeyboardSelectionHandler, SRID.KeySelectToWindowBottom, SRID.KeySelectToWindowBottomDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToDocumentStart, new ExecutedRoutedEventHandler(OnSelectToDocumentStart), queryStatusKeyboardSelectionHandler, SRID.KeySelectToDocumentStart, SRID.KeySelectToDocumentStartDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SelectToDocumentEnd, new ExecutedRoutedEventHandler(OnSelectToDocumentEnd), queryStatusKeyboardSelectionHandler, SRID.KeySelectToDocumentEnd, SRID.KeySelectToDocumentEndDisplayString);
        }
コード例 #28
0
        private ICommand RegisterCommand(
            string text, string name, InputGesture[] inputGestures,
            ExecutedRoutedEventHandler executed,
            CanExecuteRoutedEventHandler canExecute)
        {
            RoutedUICommand command = new RoutedUICommand(text, name, GetType(), new InputGestureCollection(inputGestures));
            CommandBinding  binding = new CommandBinding(command, executed, canExecute);

            AddCommandBinding(binding);

            return(command);
        }
コード例 #29
0
ファイル: CommandBinding.cs プロジェクト: i-kostikov/wpf
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="command">Command associated with this binding.</param>
        /// <param name="executed">Handler associated with executing the command.</param>
        /// <param name="canExecute">Handler associated with determining if the command can execute.</param>
        public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
        {
            _command = command ?? throw new ArgumentNullException(nameof(command));

            if (executed is not null)
            {
                Executed += executed;
            }
            if (canExecute is not null)
            {
                CanExecute += canExecute;
            }
        }
コード例 #30
0
ファイル: TextEditorTables.cs プロジェクト: v-zbsail/wpf
        //------------------------------------------------------
        //
        //  Class Internal Methods
        //
        //------------------------------------------------------

        #region Class Internal Methods

        // Registers all text editing command handlers for a given control type
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        {
            var onTableCommand   = new ExecutedRoutedEventHandler(OnTableCommand);
            var onQueryStatusNYI = new CanExecuteRoutedEventHandler(OnQueryStatusNYI);

            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertTable, onTableCommand, onQueryStatusNYI, KeyInsertTable, SRID.KeyInsertTableDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertRows, onTableCommand, onQueryStatusNYI, KeyInsertRows, SRID.KeyInsertRowsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertColumns, onTableCommand, onQueryStatusNYI, KeyInsertColumns, SRID.KeyInsertColumnsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteRows, onTableCommand, onQueryStatusNYI, SRID.KeyDeleteRows, SRID.KeyDeleteRowsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteColumns, onTableCommand, onQueryStatusNYI, KeyDeleteColumns, SRID.KeyDeleteColumnsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MergeCells, onTableCommand, onQueryStatusNYI, KeyMergeCells, SRID.KeyMergeCellsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SplitCell, onTableCommand, onQueryStatusNYI, KeySplitCell, SRID.KeySplitCellDisplayString);
        }
コード例 #31
0
        //------------------------------------------------------
        //
        //  Class Internal Methods
        //
        //------------------------------------------------------

        #region Class Internal Methods

        // Registers all text editing command handlers for a given control type
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        {
            var onTableCommand = new ExecutedRoutedEventHandler(OnTableCommand);
            var onQueryStatusNYI = new CanExecuteRoutedEventHandler(OnQueryStatusNYI);
            
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertTable   , onTableCommand, onQueryStatusNYI, SRID.KeyInsertTable, SRID.KeyInsertTableDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertRows    , onTableCommand, onQueryStatusNYI, SRID.KeyInsertRows, SRID.KeyInsertRowsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertColumns , onTableCommand, onQueryStatusNYI, SRID.KeyInsertColumns, SRID.KeyInsertColumnsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteRows    , onTableCommand, onQueryStatusNYI, SRID.KeyDeleteRows, SRID.KeyDeleteRowsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteColumns , onTableCommand, onQueryStatusNYI, SRID.KeyDeleteColumns, SRID.KeyDeleteColumnsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MergeCells    , onTableCommand, onQueryStatusNYI, SRID.KeyMergeCells, SRID.KeyMergeCellsDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SplitCell     , onTableCommand, onQueryStatusNYI, SRID.KeySplitCell, SRID.KeySplitCellDisplayString);
        }
コード例 #32
0
ファイル: SdrToolbar.xaml.cs プロジェクト: radtek/Shopdrawing
        public SdrToolbar()
        {
            InitializeComponent();
            ExecutedRoutedEventHandler   onExecutedCmd;
            CanExecuteRoutedEventHandler onCanExecuteCmd;

            onExecutedCmd   = new ExecutedRoutedEventHandler(OnExecutedCmd);
            onCanExecuteCmd = new CanExecuteRoutedEventHandler(OnCanExecuteCmd);
            foreach (RoutedUICommand cmd in m_arrCommands)
            {
                CommandBindings.Add(new CommandBinding(cmd, onExecutedCmd, onCanExecuteCmd));
            }
        }
コード例 #33
0
        // Token: 0x060038DE RID: 14558 RVA: 0x001010F4 File Offset: 0x000FF2F4
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        {
            ExecutedRoutedEventHandler   executedRoutedEventHandler   = new ExecutedRoutedEventHandler(TextEditorTables.OnTableCommand);
            CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(TextEditorTables.OnQueryStatusNYI);

            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertTable, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyInsertTable", "KeyInsertTableDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertRows, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyInsertRows", "KeyInsertRowsDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.InsertColumns, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyInsertColumns", "KeyInsertColumnsDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteRows, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyDeleteRows", "KeyDeleteRowsDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DeleteColumns, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyDeleteColumns", "KeyDeleteColumnsDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.MergeCells, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeyMergeCells", "KeyMergeCellsDisplayString");
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.SplitCell, executedRoutedEventHandler, canExecuteRoutedEventHandler, "KeySplitCell", "KeySplitCellDisplayString");
        }
コード例 #34
0
ファイル: ControllerBase.cs プロジェクト: azanium/Battleboard
        public virtual void Bind(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
        {
            if (View != null)
            {
                CommandBinding binding = new CommandBinding(command, executed, canExecute);
                View.CommandBindings.Add(binding);

                UnBind(command);

                if (!_bindings.ContainsKey(command))
                    _bindings.Add(command, binding);
            }
        }
コード例 #35
0
        private void BindCommandAndEvent(RoutedUICommand command, ExecutedRoutedEventHandler execute,
                                         CanExecuteRoutedEventHandler canExecute)
        {
            var binding = new CommandBinding(command,
                                             execute,
                                             canExecute
                                             );



            // Register CommandBinding for all windows.
            CommandManager.RegisterClassCommandBinding(typeof(Window), binding);
        }
コード例 #36
0
        public void CreateCommandBinding(RoutedUICommand command, ExecutedRoutedEventHandler execute,
                                         CanExecuteRoutedEventHandler canExecute)
        {
            var binding = new CommandBinding(command,
                                             execute,
                                             canExecute
                                             );



            // Register CommandBinding for all windows.
            CommandManager.RegisterClassCommandBinding(/*typeof(UserControl)*//*typeof(Control)*/ typeof(FrameworkElement), binding);
        }
コード例 #37
0
        private static void HandleExcute()
        {
            InsertFractionExcuted = (s, e) => {
                insertFraction(s as RichTextEditor);
            };

            InsertFractionCanExcute = (s, e) => {
                e.CanExecute = canInsertFraction(s as RichTextEditor);
            };

            EditFractionExcuted = (s, e) =>
            {
                editFraction(s as RichTextEditor);
            };

            EditFractionCanExcute = (s, e) =>
            {
                e.CanExecute = canEditFraction(s as RichTextEditor);
            };

            SuperscriptExcuted = (s, e) =>
            {
                superscript(s as RichTextEditor);
            };

            SuperscriptCanExcute = (s, e) =>
            {
                e.CanExecute = canSuperscript(s as RichTextEditor);
            };

            SubscriptExcuted = (s, e) =>
            {
                subscript(s as RichTextEditor);
            };

            SubscriptCanExcute = (s, e) =>
            {
                e.CanExecute = canSubscript(s as RichTextEditor);
            };

            InsertBlankExcuted = (s, e) =>
            {
                insertBlank(s as RichTextEditor);
            };

            InsertBlankCanExcute = (s, e) =>
            {
                e.CanExecute = canInsertBlank(s as RichTextEditor);
            };
        }
コード例 #38
0
        private void AllowImagePaste()
        {
            // AvalonEdit only allows text paste. Hack the command to allow otherwise.
            var cmd = EditBox.TextArea.DefaultInputHandler.Editing.CommandBindings.FirstOrDefault(cb => cb.Command == Paste);

            if (cmd == null)
            {
                return;
            }

            CanExecuteRoutedEventHandler canExecute = (sender, args) =>
                                                      args.CanExecute = EditBox.TextArea?.Document != null &&
                                                                        EditBox.TextArea.ReadOnlySectionProvider.CanInsert(EditBox.TextArea.Caret.Offset);

            ExecutedRoutedEventHandler execute = null;

            execute = (sender, args) =>
            {
                if (System.Windows.Clipboard.ContainsText())
                {
                    // WPF won't continue routing the command if there's PreviewExecuted handler.
                    // So, remove it, call Execute and reinstall the handler.
                    // Hack, hack hack...
                    try
                    {
                        cmd.PreviewExecuted -= execute;
                        cmd.Command.Execute(args.Parameter);
                    }
                    finally
                    {
                        cmd.PreviewExecuted += execute;
                    }
                }
                else if (System.Windows.Clipboard.ContainsImage())
                {
                    var dialog = new ImageDropDialog
                    {
                        Owner             = Application.Current.MainWindow,
                        TextEditor        = EditBox,
                        DocumentFileName  = FileName,
                        UseClipboardImage = true
                    };
                    dialog.ShowDialog();
                    args.Handled = true;
                }
            };

            cmd.CanExecute      += canExecute;
            cmd.PreviewExecuted += execute;
        }
コード例 #39
0
        private ICommand RegisterCommand(
            string text, string name,
            InputGesture[] inputGestures,
            ExecutedRoutedEventHandler executed,
            CanExecuteRoutedEventHandler canExecute)
        {
            var command        = new RoutedUICommand(text, name, this.GetType(), new InputGestureCollection(inputGestures));
            var commandBinding = new CommandBinding(command, executed, canExecute);

            CommandManager.RegisterClassCommandBinding(this.GetType(), commandBinding);
            CommandBindings.Add(commandBinding);

            return(command);
        }
コード例 #40
0
        public TableViewScrollViewer()
        {
            ExecutedRoutedEventHandler   executedRoutedEventHandler   = new ExecutedRoutedEventHandler(this.OnScrollCommand);
            CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(this.OnQueryScrollCommand);

            this.CommandBindings.Add(
                new CommandBinding(ScrollBar.PageLeftCommand,
                                   executedRoutedEventHandler,
                                   canExecuteRoutedEventHandler));

            this.CommandBindings.Add(
                new CommandBinding(ScrollBar.PageRightCommand,
                                   executedRoutedEventHandler,
                                   canExecuteRoutedEventHandler));
        }
コード例 #41
0
    public TableViewScrollViewer()
    {
      ExecutedRoutedEventHandler executedRoutedEventHandler = new ExecutedRoutedEventHandler( this.OnScrollCommand );
      CanExecuteRoutedEventHandler canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler( this.OnQueryScrollCommand );

      this.CommandBindings.Add(
        new CommandBinding( ScrollBar.PageLeftCommand,
        executedRoutedEventHandler,
        canExecuteRoutedEventHandler ) );

      this.CommandBindings.Add(
        new CommandBinding( ScrollBar.PageRightCommand,
        executedRoutedEventHandler,
        canExecuteRoutedEventHandler ) );
    }
コード例 #42
0
 public RegisterCommandBindings(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     this._command = command;
     if (executed != null)
     {
         this.Executed += executed;
     }
     if (canExecute != null)
     {
         this.CanExecute += canExecute;
     }
 }
コード例 #43
0
        //-----------------------------------------------------
        //
        //  Class Internal Methods
        // 
        //-----------------------------------------------------
 
        #region Class Internal Methods 

        // Registers all text editing command handlers for a given control type 
        internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool registerEventListeners)
        {
            CanExecuteRoutedEventHandler onQueryStatusNYI = new CanExecuteRoutedEventHandler(OnQueryStatusNYI);
 
            if (acceptsRichContent)
            { 
                // Editing Commands: Paragraph Editing 
                // -----------------------------------
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.AlignLeft                 , new ExecutedRoutedEventHandler(OnAlignLeft)                 , onQueryStatusNYI, SRID.KeyAlignLeft,             SRID.KeyAlignLeftDisplayString             ); 
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.AlignCenter               , new ExecutedRoutedEventHandler(OnAlignCenter)               , onQueryStatusNYI, SRID.KeyAlignCenter,           SRID.KeyAlignCenterDisplayString           );
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.AlignRight                , new ExecutedRoutedEventHandler(OnAlignRight)                , onQueryStatusNYI, SRID.KeyAlignRight,            SRID.KeyAlignRightDisplayString            );
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.AlignJustify              , new ExecutedRoutedEventHandler(OnAlignJustify)              , onQueryStatusNYI, SRID.KeyAlignJustify,          SRID.KeyAlignJustifyDisplayString          );
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplySingleSpace          , new ExecutedRoutedEventHandler(OnApplySingleSpace)          , onQueryStatusNYI, SRID.KeyApplySingleSpace,      SRID.KeyApplySingleSpaceDisplayString      ); 
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyOneAndAHalfSpace     , new ExecutedRoutedEventHandler(OnApplyOneAndAHalfSpace)     , onQueryStatusNYI, SRID.KeyApplyOneAndAHalfSpace, SRID.KeyApplyOneAndAHalfSpaceDisplayString );
                CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyDoubleSpace          , new ExecutedRoutedEventHandler(OnApplyDoubleSpace)          , onQueryStatusNYI, SRID.KeyApplyDoubleSpace,      SRID.KeyApplyDoubleSpaceDisplayString      ); 
            } 

            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyParagraphFlowDirectionLTR, new ExecutedRoutedEventHandler(OnApplyParagraphFlowDirectionLTR), onQueryStatusNYI); 
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyParagraphFlowDirectionRTL, new ExecutedRoutedEventHandler(OnApplyParagraphFlowDirectionRTL), onQueryStatusNYI);
        }
コード例 #44
0
        //------------------------------------------------------
        //
        //  Class Internal Methods
        //
        //------------------------------------------------------

        #region Class Internal Methods

        // Registers all text editing command handlers for a given control type
        internal static void _RegisterClassHandlers(Type controlType, bool registerEventListeners)
        {
            var onQueryStatusNYI = new CanExecuteRoutedEventHandler(OnQueryStatusNYI);

            // Editing Commands: Character Editing
            // -----------------------------------
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ResetFormat                  , new ExecutedRoutedEventHandler(OnResetFormat)       , onQueryStatusNYI, SRID.KeyResetFormat, SRID.KeyResetFormatDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleBold                   , new ExecutedRoutedEventHandler(OnToggleBold)        , onQueryStatusNYI, SRID.KeyToggleBold, SRID.KeyToggleBoldDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleItalic                 , new ExecutedRoutedEventHandler(OnToggleItalic)      , onQueryStatusNYI, SRID.KeyToggleItalic, SRID.KeyToggleItalicDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleUnderline              , new ExecutedRoutedEventHandler(OnToggleUnderline)   , onQueryStatusNYI, SRID.KeyToggleUnderline, SRID.KeyToggleUnderlineDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleSubscript              , new ExecutedRoutedEventHandler(OnToggleSubscript)   , onQueryStatusNYI, SRID.KeyToggleSubscript, SRID.KeyToggleSubscriptDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleSuperscript            , new ExecutedRoutedEventHandler(OnToggleSuperscript) , onQueryStatusNYI, SRID.KeyToggleSuperscript, SRID.KeyToggleSuperscriptDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.IncreaseFontSize             , new ExecutedRoutedEventHandler(OnIncreaseFontSize)  , onQueryStatusNYI, SRID.KeyIncreaseFontSize, SRID.KeyIncreaseFontSizeDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.DecreaseFontSize             , new ExecutedRoutedEventHandler(OnDecreaseFontSize)  , onQueryStatusNYI, SRID.KeyDecreaseFontSize, SRID.KeyDecreaseFontSizeDisplayString);

            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyFontSize                , new ExecutedRoutedEventHandler(OnApplyFontSize)     , onQueryStatusNYI, SRID.KeyApplyFontSize, SRID.KeyApplyFontSizeDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyFontFamily              , new ExecutedRoutedEventHandler(OnApplyFontFamily)   , onQueryStatusNYI, SRID.KeyApplyFontFamily, SRID.KeyApplyFontFamilyDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyForeground              , new ExecutedRoutedEventHandler(OnApplyForeground)   , onQueryStatusNYI, SRID.KeyApplyForeground, SRID.KeyApplyForegroundDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyBackground              , new ExecutedRoutedEventHandler(OnApplyBackground)   , onQueryStatusNYI, SRID.KeyApplyBackground, SRID.KeyApplyBackgroundDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ToggleSpellCheck             , new ExecutedRoutedEventHandler(OnToggleSpellCheck)  , onQueryStatusNYI, SRID.KeyToggleSpellCheck, SRID.KeyToggleSpellCheckDisplayString);
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyInlineFlowDirectionRTL  , new ExecutedRoutedEventHandler(OnApplyInlineFlowDirectionRTL), new CanExecuteRoutedEventHandler(OnQueryStatusNYI));
            CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.ApplyInlineFlowDirectionLTR  , new ExecutedRoutedEventHandler(OnApplyInlineFlowDirectionLTR), new CanExecuteRoutedEventHandler(OnQueryStatusNYI));
        }
コード例 #45
0
ファイル: HexBox.cs プロジェクト: lovebanyi/dnSpy
 void Add(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler exec, CanExecuteRoutedEventHandler canExec = null)
 {
     this.CommandBindings.Add(new CommandBinding(command, exec, canExec));
     this.InputBindings.Add(new KeyBinding(command, key, modifiers));
 }
コード例 #46
0
ファイル: ReplEditorUI.cs プロジェクト: GreenDamTan/dnSpy
		void AddBinding(RoutedUICommand routedCmd, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute) {
			Remove(this.textEditor.TextArea.CommandBindings, routedCmd);
			this.textEditor.TextArea.CommandBindings.Add(new CommandBinding(routedCmd, executed, canExecute));
		}
コード例 #47
0
ファイル: CommandHelpers.cs プロジェクト: sjyanxin/WPFSource
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, Key key, ModifierKeys modifierKeys, 
                                             ExecutedRoutedEventHandler executedRoutedEventHandler, CanExecuteRoutedEventHandler canExecuteRoutedEventHandler) 
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, new KeyGesture(key, modifierKeys)); 
 }
コード例 #48
0
ファイル: InputBox.cs プロジェクト: QuocHuy7a10/Arianrhod
 protected override void OnInitialized(EventArgs e)
 {
     base.AllowDrop = true;
     base.OnInitialized(e);
     base.Unloaded += new RoutedEventHandler(this.InputBox_Unloaded);
     this.pastingEventHandler = new DataObjectPastingEventHandler(this.InputBox_Pasting);
     this.copyingEventHandler = new DataObjectCopyingEventHandler(this.InputBox_Copying);
     base.AddHandler(DataObject.PastingEvent, this.pastingEventHandler, true);
     base.AddHandler(DataObject.CopyingEvent, this.copyingEventHandler, true);
     this.clickedEventHandler = new ImageEx.ClickedEventHandler(this.InputBox_ImageClicked);
     base.AddHandler(ImageEx.ClickedEvent, this.clickedEventHandler, false);
     base.FontFamily = defaultFontFamily;
     base.FontSize = 12.0;
     this.executedRoutedEventHandler = new ExecutedRoutedEventHandler(this.ExecutedRoutedEvent);
     this.canExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(this.CanExecuteRoutedEvent);
     base.AddHandler(CommandManager.PreviewExecutedEvent, this.executedRoutedEventHandler, true);
     base.AddHandler(CommandManager.PreviewCanExecuteEvent, this.canExecuteRoutedEventHandler, true);
 }
コード例 #49
0
 public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
 {
 }
コード例 #50
0
ファイル: DocumentViewer.cs プロジェクト: JianwenSun/cc
        private static void CreateCommandBindings()
        {
            // Create our generic ExecutedRoutedEventHandler.
            ExecutedRoutedEventHandler executeHandler = new ExecutedRoutedEventHandler(ExecutedRoutedEventHandler);

            // Create our generic QueryEnabledStatusHandler
            CanExecuteRoutedEventHandler queryEnabledHandler = new CanExecuteRoutedEventHandler(QueryEnabledHandler);

            //
            // Command: ViewThumbnails
            //          Tells DocumentViewer to display thumbnails.
            _viewThumbnailsCommand = new RoutedUICommand(SR.Get(SRID.DocumentViewerViewThumbnailsCommandText),
                "ViewThumbnailsCommand",
                typeof(DocumentViewer),
                null);

            CommandHelpers.RegisterCommandHandler( typeof(DocumentViewer),
                _viewThumbnailsCommand,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            //
            // Command: FitToWidth
            //          Tells DocumentViewer to zoom to the document width.
            _fitToWidthCommand = new RoutedUICommand(
                SR.Get(SRID.DocumentViewerViewFitToWidthCommandText),
                "FitToWidthCommand",
                typeof(DocumentViewer),
                null);

            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                _fitToWidthCommand,
                executeHandler,
                queryEnabledHandler,
                new KeyGesture(Key.D2, ModifierKeys.Control));

            //
            // Command: FitToHeight
            //          Tells DocumentViewer to zoom to the document height.
            _fitToHeightCommand = new RoutedUICommand(
                SR.Get(SRID.DocumentViewerViewFitToHeightCommandText),
                "FitToHeightCommand",
                typeof(DocumentViewer),
                null);

            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                _fitToHeightCommand,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            //
            // Command: MaxPagesAcross
            //          Sets the MaxPagesAcross to the value provided.
            _fitToMaxPagesAcrossCommand = new RoutedUICommand(
                SR.Get(SRID.DocumentViewerViewFitToMaxPagesAcrossCommandText),
                "FitToMaxPagesAcrossCommand",
                typeof(DocumentViewer),
                null);

            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                _fitToMaxPagesAcrossCommand,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            #region Library Commands

            // Command: ApplicationCommands.Find - Ctrl+F
            //          Invokes DocumentViewer's Find dialog.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ApplicationCommands.Find,
                executeHandler,
                queryEnabledHandler);

            //
            // Command: ComponentCommands.ScrollPageUp - PageUp
            //          Causes DocumentViewer to scroll a Viewport up.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.ScrollPageUp,
                executeHandler,
                queryEnabledHandler,
                Key.PageUp);

            //
            // Command: ComponentCommands.ScrollPageDown - PageDown
            //          Causes DocumentViewer to scroll a Viewport down.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.ScrollPageDown,
                executeHandler,
                queryEnabledHandler,
                Key.PageDown);

            //
            // Command: ComponentCommands.ScrollPageLeft
            //          Causes DocumentViewer to scroll a Viewport to the left.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.ScrollPageLeft,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            //
            // Command: ComponentCommands.ScrollPageRight
            //          Causes DocumentViewer to scroll a Viewport to the right.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.ScrollPageRight,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            //
            // Command: ComponentCommands.MoveUp - Up
            //          Causes DocumentViewer to scroll the Viewport up by 16px.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.MoveUp,
                executeHandler,
                queryEnabledHandler,
                Key.Up);

            //
            // Command: ComponentCommands.MoveDown - Down
            //          Causes DocumentViewer to scroll the Viewport down by 16px.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.MoveDown,
                executeHandler,
                queryEnabledHandler,
                Key.Down);

            //
            // Command: ComponentCommands.MoveLeft - Left
            //          Causes DocumentViewer to scroll a Viewport left by 16px.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.MoveLeft,
                executeHandler,
                queryEnabledHandler,
                Key.Left);

            //
            // Command: ComponentCommands.MoveRight - Right
            //          Causes DocumentViewer to scroll a Viewport right by 16px.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                ComponentCommands.MoveRight,
                executeHandler,
                queryEnabledHandler,
                Key.Right);

            //
            // Command: NavigationCommands.Zoom
            //          Sets DocumentViewer's Zoom to the specified level.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.Zoom,
                executeHandler,
                queryEnabledHandler);
                //no key gesture

            //
            // Command: NavigationCommands.IncreaseZoom
            //          Causes DocumentViewer to zoom in on the content.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.IncreaseZoom,
                executeHandler,
                queryEnabledHandler,
                // Ctrl+Numpad '+'
                new KeyGesture(Key.Add, ModifierKeys.Control),
                // Ctrl+Numpad '+' (In case shift is held down)
                new KeyGesture(Key.Add, ModifierKeys.Shift | ModifierKeys.Control),
                // Ctrl+'+'
                new KeyGesture(Key.OemPlus, ModifierKeys.Control),
                // Ctrl+'+' (In case shift is held down)
                new KeyGesture(Key.OemPlus, ModifierKeys.Shift | ModifierKeys.Control));

            //
            // Command: NavigationCommands.DecreaseZoom
            //          Causes DocumentViewer to zoom out of the content.
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.DecreaseZoom,
                executeHandler,
                queryEnabledHandler,
                // Ctrl+Numpad '-'
                new KeyGesture(Key.Subtract, ModifierKeys.Control),
                // Ctrl+Numpad '-' (In case shift is held down)
                new KeyGesture(Key.Subtract, ModifierKeys.Shift | ModifierKeys.Control),
                // Ctrl+'-'
                new KeyGesture(Key.OemMinus, ModifierKeys.Control),
                // Ctrl+'-' (In case shift is held down)
                new KeyGesture(Key.OemMinus, ModifierKeys.Shift | ModifierKeys.Control));

            // Command: NavigationCommands.PreviousPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.PreviousPage,
                executeHandler,
                queryEnabledHandler,
                new KeyGesture(Key.PageUp, ModifierKeys.Control));

            // Command: NavigationCommands.NextPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.NextPage,
                executeHandler,
                queryEnabledHandler,
                new KeyGesture(Key.PageDown, ModifierKeys.Control));

            // Command: NavigationCommands.FirstPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.FirstPage,
                executeHandler,
                queryEnabledHandler,
                new KeyGesture(Key.Home, ModifierKeys.Control));

            // Command: NavigationCommands.FirstPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewer),
                NavigationCommands.LastPage,
                executeHandler,
                queryEnabledHandler,
                new KeyGesture(Key.End, ModifierKeys.Control));

            #endregion Library Commands

            //Register input bindings for keyboard shortcuts that require
            //Command Parameters:

            //Zoom 100%: Requires a CommandParameter of 100.0 with the Zoom Command.
            //Bound to Ctrl+1.
            InputBinding zoom100InputBinding =
                new InputBinding(NavigationCommands.Zoom,
                new KeyGesture(Key.D1, ModifierKeys.Control));
            zoom100InputBinding.CommandParameter = 100.0;

            CommandManager.RegisterClassInputBinding(typeof(DocumentViewer),
                zoom100InputBinding);

            //Whole Page: Requires a CommandParameter of 1 with the FitToMaxPagesAcross Command.
            //Bound to Ctrl+3.
            InputBinding wholePageInputBinding =
                            new InputBinding(DocumentViewer.FitToMaxPagesAcrossCommand,
                            new KeyGesture(Key.D3, ModifierKeys.Control));
            wholePageInputBinding.CommandParameter = 1;

            CommandManager.RegisterClassInputBinding(typeof(DocumentViewer),
                wholePageInputBinding);

            //Two Pages: Requires a CommandParameter of 2 with the FitToMaxPagesAcross Command.
            //Bound to Ctrl+4.
            InputBinding twoPagesInputBinding =
                            new InputBinding(DocumentViewer.FitToMaxPagesAcrossCommand,
                            new KeyGesture(Key.D4, ModifierKeys.Control));
            twoPagesInputBinding.CommandParameter = 2;

            CommandManager.RegisterClassInputBinding(typeof(DocumentViewer),
                twoPagesInputBinding);


        }
コード例 #51
0
ファイル: ScrollViewer.cs プロジェクト: JianwenSun/cc
        private static void InitializeCommands()
        {
            ExecutedRoutedEventHandler executeScrollCommandEventHandler = new ExecutedRoutedEventHandler(OnScrollCommand);
            CanExecuteRoutedEventHandler canExecuteScrollCommandEventHandler = new CanExecuteRoutedEventHandler(OnQueryScrollCommand);

            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.LineLeftCommand,          executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.LineRightCommand,         executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.PageLeftCommand,          executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.PageRightCommand,         executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.LineUpCommand,            executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.LineDownCommand,          executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.PageUpCommand,            executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.PageDownCommand,          executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToLeftEndCommand,   executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToRightEndCommand,  executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToEndCommand,       executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToHomeCommand,      executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToTopCommand,       executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToBottomCommand,    executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToHorizontalOffsetCommand,  executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.ScrollToVerticalOffsetCommand,    executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.DeferScrollToHorizontalOffsetCommand, executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ScrollBar.DeferScrollToVerticalOffsetCommand,   executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);

            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ComponentCommands.ScrollPageUp,     executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
            CommandHelpers.RegisterCommandHandler(typeof(ScrollViewer), ComponentCommands.ScrollPageDown,   executeScrollCommandEventHandler, canExecuteScrollCommandEventHandler);
        }
コード例 #52
0
        /// <summary>
        /// Set up Command and RoutedCommand bindings.
        /// </summary>
        private static void CreateCommandBindings()
        {
            ExecutedRoutedEventHandler executedHandler;
            CanExecuteRoutedEventHandler canExecuteHandler;

            // Create our generic ExecutedRoutedEventHandler.
            executedHandler = new ExecutedRoutedEventHandler(ExecutedRoutedEventHandler);
            // Create our generic QueryEnabledStatusHandler
            canExecuteHandler = new CanExecuteRoutedEventHandler(CanExecuteRoutedEventHandler);

            // Command: NavigationCommands.PreviousPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), NavigationCommands.PreviousPage,
                executedHandler, canExecuteHandler); // no key gesture

            // Command: NavigationCommands.NextPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), NavigationCommands.NextPage,
                executedHandler, canExecuteHandler); // no key gesture

            // Command: NavigationCommands.FirstPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), NavigationCommands.FirstPage,
                executedHandler, canExecuteHandler); // no key gesture

            // Command: NavigationCommands.LastPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), NavigationCommands.LastPage,
                executedHandler, canExecuteHandler); // no key gesture

            // Command: NavigationCommands.GoToPage
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), NavigationCommands.GoToPage,
                executedHandler, canExecuteHandler); // no key gesture

            // Command: ApplicationCommands.Print
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), ApplicationCommands.Print,
                executedHandler, canExecuteHandler, new KeyGesture(Key.P, ModifierKeys.Control));

            // Command: ApplicationCommands.CancelPrint
            CommandHelpers.RegisterCommandHandler(typeof(DocumentViewerBase), ApplicationCommands.CancelPrint,
                executedHandler, canExecuteHandler); // no key gesture

            // Register editing command handlers - After our commands to let editor handle them first
            TextEditor.RegisterCommandHandlers(typeof(DocumentViewerBase), /*acceptsRichContent:*/true, /*readOnly:*/!IsEditingEnabled, /*registerEventListeners*/true);
        }
コード例 #53
0
        /// <summary>
        /// Class Ctor
        /// </summary>
        public MainWindow() {
            SrcChess2.Properties.Settings   settings;
            ExecutedRoutedEventHandler      onExecutedCmd;
            CanExecuteRoutedEventHandler    onCanExecuteCmd;
            PieceSet                        pieceSet;

            InitializeComponent();
            settings                            = SrcChess2.Properties.Settings.Default;
            m_listPieceSet                      = PieceSetStandard.LoadPieceSetFromResource();
            pieceSet                            = m_listPieceSet[settings.PieceSet];
            m_chessCtl.Father                   = this;
            m_chessCtl.LiteCellColor            = NameToColor(settings.LiteCellColor);
            m_chessCtl.DarkCellColor            = NameToColor(settings.DarkCellColor);
            m_chessCtl.WhitePieceColor          = NameToColor(settings.WhitePieceColor);
            m_chessCtl.BlackPieceColor          = NameToColor(settings.BlackPieceColor);
            m_colorBackground                   = NameToColor(settings.BackgroundColor);
            Background                          = new SolidColorBrush(m_colorBackground);
            m_boardEvalUtil                     = new BoardEvaluationUtil();
            SetSearchModeFromSetting(settings);
            m_chessCtl.UpdateCmdState          += new EventHandler(m_chessCtl_UpdateCmdState);
            PlayingMode                         = PlayingModeE.PlayerAgainstComputer;
            m_eComputerPlayingColor             = ChessBoard.PlayerColorE.Black;
            m_lostPieceBlack.ChessBoardControl  = m_chessCtl;
            m_lostPieceBlack.Color              = true;
            m_lostPieceWhite.ChessBoardControl  = m_chessCtl;
            m_lostPieceWhite.Color              = false;
            m_moveViewer.NewMoveSelected       += new MoveViewer.NewMoveSelectedHandler(m_moveViewer_NewMoveSelected);
            m_moveViewer.DisplayMode            = (settings.MoveNotation == 0) ? MoveViewer.DisplayModeE.MovePos : MoveViewer.DisplayModeE.PGN;
            m_chessCtl.MoveListUI               = this;
            m_chessCtl.MoveSelected            += new ChessBoardControl.MoveSelectedEventHandler(m_chessCtl_MoveSelected);
            m_chessCtl.QueryPiece              += new ChessBoardControl.QueryPieceEventHandler(m_chessCtl_QueryPiece);
            m_chessCtl.QueryPawnPromotionType  += new ChessBoardControl.QueryPawnPromotionTypeEventHandler(m_chessCtl_QueryPawnPromotionType);
            m_bSecondThreadBusy                 = false;
            m_dispatcherTimer                   = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, new EventHandler(dispatcherTimer_Tick), Dispatcher);
            m_dispatcherTimer.Start();
            SetCmdState();
            ShowSearchMode();
            mnuOptionFlashPiece.IsChecked       = settings.FlashPiece;
            mnuOptionPGNNotation.IsChecked      = (m_moveViewer.DisplayMode == MoveViewer.DisplayModeE.PGN);
            PieceSet                            = pieceSet;
            onExecutedCmd                       = new ExecutedRoutedEventHandler(OnExecutedCmd);
            onCanExecuteCmd                     = new CanExecuteRoutedEventHandler(OnCanExecuteCmd);
            foreach (RoutedUICommand cmd in m_arrCommands) {
                CommandBindings.Add(new CommandBinding(cmd, onExecutedCmd, onCanExecuteCmd));
            }
        }
コード例 #54
0
ファイル: MainWindow.xaml.cs プロジェクト: DeepSkyFire/dnSpy
 public void Add(ICommand command, ExecutedRoutedEventHandler exec, CanExecuteRoutedEventHandler canExec, ModifierKeys modifiers1, Key key1, ModifierKeys modifiers2 = ModifierKeys.None, Key key2 = Key.None, ModifierKeys modifiers3 = ModifierKeys.None, Key key3 = Key.None)
 {
     this.CommandBindings.Add(new CommandBinding(command, exec, canExec));
     this.InputBindings.Add(new KeyBinding(command, key1, modifiers1));
     if (key2 != Key.None)
         this.InputBindings.Add(new KeyBinding(command, key2, modifiers2));
     if (key3 != Key.None)
         this.InputBindings.Add(new KeyBinding(command, key3, modifiers3));
 }
コード例 #55
0
        /// <summary>
        /// Set up Command and RoutedCommand bindings.
        /// </summary>
        private static void CreateCommandBindings()
        {
            ExecutedRoutedEventHandler executedHandler;
            CanExecuteRoutedEventHandler canExecuteHandler;

            // Create our generic ExecutedRoutedEventHandler.
            executedHandler = new ExecutedRoutedEventHandler(ExecutedRoutedEventHandler);
            // Create our generic CanExecuteRoutedEventHandler
            canExecuteHandler = new CanExecuteRoutedEventHandler(CanExecuteRoutedEventHandler);

            // Command: ApplicationCommands.Find
            CommandHelpers.RegisterCommandHandler(typeof(FlowDocumentPageViewer), ApplicationCommands.Find,
                executedHandler, canExecuteHandler);

            // Command: NavigationCommands.IncreaseZoom
            CommandHelpers.RegisterCommandHandler(typeof(FlowDocumentPageViewer), NavigationCommands.IncreaseZoom,
                executedHandler, canExecuteHandler, new KeyGesture(Key.OemPlus, ModifierKeys.Control));

            // Command: NavigationCommands.DecreaseZoom
            CommandHelpers.RegisterCommandHandler(typeof(FlowDocumentPageViewer), NavigationCommands.DecreaseZoom,
                executedHandler, canExecuteHandler, new KeyGesture(Key.OemMinus, ModifierKeys.Control));

            // Register input bindings
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.PreviousPage, new KeyGesture(Key.Left)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.PreviousPage, new KeyGesture(Key.Up)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.PreviousPage, new KeyGesture(Key.PageUp)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.NextPage, new KeyGesture(Key.Right)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.NextPage, new KeyGesture(Key.Down)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.NextPage, new KeyGesture(Key.PageDown)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.FirstPage, new KeyGesture(Key.Home)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.FirstPage, new KeyGesture(Key.Home, ModifierKeys.Control)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.LastPage, new KeyGesture(Key.End)));
            CommandManager.RegisterClassInputBinding(typeof(FlowDocumentPageViewer), new InputBinding(NavigationCommands.LastPage, new KeyGesture(Key.End, ModifierKeys.Control)));
        }
コード例 #56
0
ファイル: CommandHelpers.cs プロジェクト: sjyanxin/WPFSource
        // 'params' based method is private.  Call sites that use this bloat unwittingly due to implicit construction of the params array that goes into IL.
        private static void PrivateRegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, 
                                                          CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, params InputGesture[] inputGestures)
        {
            // Validate parameters
            Debug.Assert(controlType != null); 
            Debug.Assert(command != null);
            Debug.Assert(executedRoutedEventHandler != null); 
            // All other parameters may be null 

            // Create command link for this command 
            CommandManager.RegisterClassCommandBinding(controlType, new CommandBinding(command, executedRoutedEventHandler, canExecuteRoutedEventHandler));

            // Create additional input binding for this command
            if (inputGestures != null) 
            {
                for (int i = 0; i < inputGestures.Length; i++) 
                { 
                    CommandManager.RegisterClassInputBinding(controlType, new InputBinding(command, inputGestures[i]));
                } 
            }

        }
コード例 #57
0
ファイル: CommandHelpers.cs プロジェクト: sjyanxin/WPFSource
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler,
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, string srid1, string srid2)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, 
                                           KeyGesture.CreateFromResourceStrings(SR.Get(srid1), SR.Get(srid2)));
 } 
コード例 #58
0
ファイル: CommandManager.cs プロジェクト: alesliehughes/olive
		public static void AddPreviewCanExecuteHandler (UIElement element, CanExecuteRoutedEventHandler handler)
		{
			if (element == null) throw new ArgumentNullException ("element");
			if (handler == null) throw new ArgumentNullException ("handler");
			element.AddHandler (PreviewCanExecuteEvent, handler);
		}
コード例 #59
0
ファイル: CommandHelpers.cs プロジェクト: sjyanxin/WPFSource
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler,
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, null); 
 }
コード例 #60
-1
 internal static void _RegisterClassHandlers(Type controlType, bool acceptsRichContent, bool readOnly, bool registerEventListeners)
 {
     CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Copy, new ExecutedRoutedEventHandler(OnCopy), new CanExecuteRoutedEventHandler(OnQueryStatusCopy), KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyCopy), SR.Get(SRID.KeyCopyDisplayString)), KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyCtrlInsert), SR.Get(SRID.KeyCtrlInsertDisplayString)));
     if (acceptsRichContent)
     {
         CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.CopyFormat, new ExecutedRoutedEventHandler(OnCopyFormat), new CanExecuteRoutedEventHandler(OnQueryStatusCopyFormat), SRID.KeyCopyFormat, SRID.KeyCopyFormatDisplayString);
     }
     if (!readOnly)
     {
         CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Cut, new ExecutedRoutedEventHandler(OnCut), new CanExecuteRoutedEventHandler(OnQueryStatusCut), KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyCut), SR.Get(SRID.KeyCutDisplayString)), KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyShiftDelete), SR.Get(SRID.KeyShiftDeleteDisplayString)));
         // temp vars to reduce code under elevation
         ExecutedRoutedEventHandler ExecutedRoutedEventHandler = new ExecutedRoutedEventHandler(OnPaste);
         CanExecuteRoutedEventHandler CanExecuteRoutedEventHandler = new CanExecuteRoutedEventHandler(OnQueryStatusPaste);
         InputGesture inputGesture = KeyGesture.CreateFromResourceStrings(SR.Get(SRID.KeyShiftInsert), SR.Get(SRID.KeyShiftInsertDisplayString));
         new UIPermission(UIPermissionClipboard.AllClipboard).Assert(); //BlessedAssert
         try
         {
             CommandHelpers.RegisterCommandHandler(controlType, ApplicationCommands.Paste, ExecutedRoutedEventHandler, CanExecuteRoutedEventHandler, inputGesture);
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
         if (acceptsRichContent)
         {
             CommandHelpers.RegisterCommandHandler(controlType, EditingCommands.PasteFormat, new ExecutedRoutedEventHandler(OnPasteFormat), new CanExecuteRoutedEventHandler(OnQueryStatusPasteFormat), SRID.KeyPasteFormat, SRID.KeyPasteFormatDisplayString);
         }
     }
 }