コード例 #1
0
 public static void AddCommandPreviewExecuteHandler(this CommandBindingCollection collection, RoutedCommand command, ExecutedRoutedEventHandler handler)
 {
     CommandBinding binding = GetOrCreateBinding(collection, command);
     // Remove the handler if it already exist
     binding.PreviewExecuted -= handler;
     binding.PreviewExecuted += 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
ファイル: 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);
 } 
コード例 #4
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)) );

        } 
コード例 #5
0
 public static void RemoveCommandExecutedHandler(this CommandBindingCollection collection, RoutedCommand command, ExecutedRoutedEventHandler handler)
 {
     CommandBinding binding = GetBinding(collection, command);
     if (binding != null)
     {
         binding.Executed -= handler;
     }
 }
コード例 #6
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);
 }
コード例 #7
0
 /// <summary>
 /// Регистрирует обработчик команды
 /// </summary>
 /// <param name="controlType">Тип контрола</param>
 /// <param name="command">Команда</param>
 /// <param name="executedRoutedEventHandler">Обработчик выполнения команды</param>
 /// <param name="canExecuteRoutedEventHandler">Обработчик проверки возможности выполнения команды</param>
 /// <param name="inputGesture">Горячая клавиша</param>
 /// <param name="inputGesture2">Горячая клавиша</param>
 public static void RegisterCommandHandler(
     Type controlType,
     RoutedCommand command,
     ExecutedRoutedEventHandler executedRoutedEventHandler,
     CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
     InputGesture inputGesture,
     InputGesture inputGesture2)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler, new[] { inputGesture, inputGesture2 });
 }
コード例 #8
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);
        }
コード例 #9
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));
        }
コード例 #10
0
        public UICommandBase(ExecutedRoutedEventHandler executeHandler, Func <object, bool> canExecuteMethod)
        {
            if (executeHandler == null || canExecuteMethod == null)
            {
                throw new ArgumentNullException("UICommandBase的参数为null");
            }

            ExecutedRoutedEvent  += executeHandler;
            this.canExecuteMethod = canExecuteMethod;
        }
コード例 #11
0
        private void AddMenuCommand(ICommand command, ExecutedRoutedEventHandler executed)
        {
            // The command can be null if a separator is intended.
            if (command == null)
            {
                return;
            }

            // Bind the command to the corresponding handler. Requires the menu to be the target of notifications in TaskbarIcon.
            CommandManager.RegisterClassCommandBinding(typeof(ContextMenu), new CommandBinding(command, executed));
        }
コード例 #12
0
        private ICommand InitMenuCommand(string commandName, string header, ExecutedRoutedEventHandler executed)
        {
            ICommand Command = (ICommand)FindResource(commandName);

            MenuHeaderTable.Add(Command, header);

            // Bind the command to the corresponding handler. Requires the menu to be the target of notifications in TaskbarIcon.
            CommandManager.RegisterClassCommandBinding(typeof(ContextMenu), new CommandBinding(Command, executed));

            return(Command);
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: CommandManager.cs プロジェクト: stanasse/olive
 public static void AddPreviewExecutedHandler(UIElement element, ExecutedRoutedEventHandler handler)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     element.AddHandler(PreviewExecutedEvent, handler);
 }
コード例 #15
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);
        }
コード例 #16
0
ファイル: CommandManager.cs プロジェクト: stanasse/olive
 public static void RemoveExecutedHandler(UIElement element, ExecutedRoutedEventHandler handler)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     element.RemoveHandler(ExecutedEvent, handler);
 }
コード例 #17
0
        private void SetupKeybind(InputGesture keyGesture, ExecutedRoutedEventHandler onPress)
        {
            var changeItemValues = new RoutedCommand();
            var ib = new InputBinding(changeItemValues, keyGesture);

            InputBindings.Add(ib);
            // Bind handler.
            var cb = new CommandBinding(changeItemValues);

            cb.Executed += onPress;
            CommandBindings.Add(cb);
        }
コード例 #18
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);
        }
コード例 #19
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);
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
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;
            }
        }
コード例 #23
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");
        }
コード例 #24
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);
            }
        }
コード例 #25
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);
        }
コード例 #26
0
        public MainWindow(ExecutedRoutedEventHandler CtrlP_CommandHandler, object CustomCommands, ExecutedRoutedEventHandler CtrlS_CommandHandler)
        {
            InitializeComponent();
            // creare obiect binding pentru comanda
            CommandBinding cmd1 = new CommandBinding();

            //asociere comanda
            cmd1.Command = ApplicationCommands.Print;
            //asociem un handler
            cmd1.Executed += new ExecutedRoutedEventHandler(CtrlP_CommandHandler);
            //adaugam la colectia CommandBindings
            this.CommandBindings.Add(cmd1);
        }
コード例 #27
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));
            }
        }
コード例 #28
0
ファイル: CommandManager.cs プロジェクト: JianwenSun/cc
        /// <summary>
        ///     Removes the handler from the element.
        /// </summary>
        /// <param name="element">The element from which to remove the handler.</param>
        /// <param name="handler">The handler to remove.</param>
        public static void RemovePreviewExecutedHandler(UIElement element, ExecutedRoutedEventHandler handler)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            element.RemoveHandler(PreviewExecutedEvent, handler);
        }
コード例 #29
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);
        }
コード例 #30
0
 private void AddHotKeys(ExecutedRoutedEventHandler handler, Key key, ModifierKeys mod = ModifierKeys.None)
 {
     try {
         RoutedCommand firstSettings = new RoutedCommand();
         firstSettings.InputGestures.Add(new KeyGesture(key, mod));
         CommandBindings.Add(new CommandBinding(firstSettings, handler));
         //private void My_first_event_handler(object sender, ExecutedRoutedEventArgs e)
         //private void My_second_event_handler(object sender, RoutedEventArgs e)
     }
     catch (Exception err)
     {
         //handle exception error
     }
 }
コード例 #31
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);
            };
        }
コード例 #32
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;
        }
コード例 #33
0
ファイル: TextBoxBase.cs プロジェクト: thrmotta/Imagin.NET
 static void OnEnableCommandChanged(UIElement Element, ExecutedRoutedEventHandler Handler, bool Enable)
 {
     if (Element != null)
     {
         if (Enable)
         {
             CommandManager.RemovePreviewExecutedHandler(Element, Handler);
         }
         else
         {
             CommandManager.AddPreviewExecutedHandler(Element, Handler);
         }
     }
 }
コード例 #34
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));
        }
コード例 #35
0
ファイル: CmdExe.cs プロジェクト: friendgo777/EDCB
            public bool                         IsReleaseItem; //コマンド実行前に選択アイテムを解除する。

            public cmdOption(ExecutedRoutedEventHandler exe
                             , CanExecuteRoutedEventHandler canExe = null
                             , cmdExeType exeType = cmdExeType.NoSetItem
                             , bool needClone     = false
                             , bool needItem      = true
                             , bool releaseItem   = false
                             )
            {
                Exe           = exe;
                CanExe        = canExe;
                ExeType       = exeType;
                IsNeedClone   = needClone;
                IsNeedItem    = needItem;
                IsReleaseItem = releaseItem;
            }
コード例 #36
0
        public static void AddCommandBinding(this UIElement uIElement,
                                             ICommand command,
                                             CanExecuteRoutedEventHandler canExecute,
                                             ExecutedRoutedEventHandler executed)
        {
            var binding = new CommandBinding
            {
                Command = command
            };

            binding.CanExecute += canExecute;
            binding.Executed   += executed;

            uIElement.CommandBindings.Add(binding);
        }
コード例 #37
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);
                }
            }
        }
コード例 #38
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 ) );
    }
コード例 #39
0
        private void CreateCommandBinding(RoutedUICommand command, ExecutedRoutedEventHandler execute,
                                          CanExecuteRoutedEventHandler canExecute)
        {
            var binding = new CommandBinding(command,
                                             execute,
                                             //DoSomething,
                                             //CanDoSomething
                                             canExecute
                                             );



            // Register CommandBinding for all windows.
            CommandManager.RegisterClassCommandBinding(typeof(Window), binding);
        }
コード例 #40
0
ファイル: WpfCommands.cs プロジェクト: zz110/dnSpy
 public void Add(RoutedCommand command, ExecutedRoutedEventHandler exec, CanExecuteRoutedEventHandler canExec, ModifierKeys modifiers1 = ModifierKeys.None, Key key1 = Key.None, ModifierKeys modifiers2 = ModifierKeys.None, Key key2 = Key.None, ModifierKeys modifiers3 = ModifierKeys.None, Key key3 = Key.None)
 {
     Add(new CommandBinding(command, exec, canExec));
     if (key1 != Key.None)
     {
         AddIfNotAdded(new KeyBinding(command, key1, modifiers1));
     }
     if (key2 != Key.None)
     {
         AddIfNotAdded(new KeyBinding(command, key2, modifiers2));
     }
     if (key3 != Key.None)
     {
         AddIfNotAdded(new KeyBinding(command, key3, modifiers3));
     }
 }
コード例 #41
0
ファイル: MainWindow.xaml.cs プロジェクト: Yegoroff/EsAdmin
        private void BindKeysAndHandler(ICommand command, KeyGesture keyGesture, ExecutedRoutedEventHandler handler)
        {
            var ib = new InputBinding(command, keyGesture);

            InputBindings.Add(ib);

            if (handler == null)
            {
                return;
            }

            var cb = new CommandBinding(command);

            cb.Executed += handler;
            CommandBindings.Add(cb);
        }
コード例 #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
        public void AddCommand(ExecutedRoutedEventHandler callback, Key key, ModifierKeys modifier)
        {
            CommandBinding cmd = new CommandBinding();

            cmd.Command = new RoutedUICommand();

            cmd.Executed   += callback;
            cmd.CanExecute += new CanExecuteRoutedEventHandler(_AlwaysCanExecute);
            this.CommandBindings.Add(cmd);
            KeyBinding CmdKey = new KeyBinding();

            CmdKey.Key       = key;
            CmdKey.Modifiers = modifier;
            CmdKey.Command   = cmd.Command;
            this.InputBindings.Add(CmdKey);
            m_keyCommands.Add(CmdKey);
        }
コード例 #44
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]));
                } 
            }

        }
コード例 #45
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);
        }
コード例 #46
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));
 }
コード例 #47
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));
		}
コード例 #48
0
		static void AddBinding(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler handler)
		{
			CommandBindings.Add(new CommandBinding(command, handler));
			InputBindings.Add(TextAreaDefaultInputHandler.CreateFrozenKeyBinding(command, modifiers, key));
		}
コード例 #49
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)); 
 }
コード例 #50
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)));
 } 
コード例 #51
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);
 }
コード例 #52
0
 public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute)
 {
 }
コード例 #53
0
 public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed)
 {
 }
コード例 #54
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)));
        }
コード例 #55
0
ファイル: CommandBinding.cs プロジェクト: sjyanxin/WPFSource
 /// <summary>
 /// Constructor 
 /// </summary>
 /// <param name="command">Command associated with this binding.</param>
 /// <param name="executed">Handler associated with executing the command.</param>
 public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed) 
     : this(command, executed, null)
 { 
 } 
コード例 #56
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);
        }
コード例 #57
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));
            }
        }
コード例 #58
0
		/// <summary>
		/// Adds a command and input binding.
		/// </summary>
		/// <param name="command">The command ID.</param>
		/// <param name="modifiers">The modifiers of the keyboard shortcut.</param>
		/// <param name="key">The key of the keyboard shortcut.</param>
		/// <param name="handler">The event handler to run when the command is executed.</param>
		public void AddBinding(ICommand command, ModifierKeys modifiers, Key key, ExecutedRoutedEventHandler handler)
		{
			this.CommandBindings.Add(new CommandBinding(command, handler));
			this.InputBindings.Add(new KeyBinding(command, key, modifiers));
		}
コード例 #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);
         }
     }
 }