示例#1
0
        /// <summary>
        /// A class handler which handles the various commands.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnExecutedCommands(object sender, ExecutedRoutedEventArgs e)
        {
            SampleWindow myWindow = (SampleWindow)sender;

            if (e.Command == ApplicationCommands.Close)
            {
                // Close the main window.
                myWindow.Close();
            }
            else if (e.Command == SampleWindow.ClearCommand)
            {
                // Clear the current strokes.
                myWindow.ClearStrokes();
            }
            else if (e.Command == SampleWindow.EditingCommand)
            {
                EditingModeId newEditingMode = (EditingModeId)e.Parameter;

                if (newEditingMode == EditingModeId.CurrentPen)
                {
                    // The Pen toolbar button is clicked.
                    // We will switch to the mode with the active pen setting.
                    newEditingMode = myWindow.CurrentPenMode;
                }
                else if (newEditingMode == EditingModeId.CurrentHighlighter)
                {
                    // The Highlighter toolbar button is clicked.
                    // We will switch to the mode with the active highlighter setting.
                    newEditingMode = myWindow.CurrentHighlighterMode;
                }
                else if (newEditingMode == EditingModeId.CurrentEraser)
                {
                    // The Eraser toolbar button is clicked.
                    // We will switch to the mode with the active eraser setting.
                    newEditingMode = myWindow.CurrentEraserMode;
                }

                // Switch to the specified mode.
                myWindow.EditingMode = newEditingMode;
            }
            else if (e.Command == SampleWindow.OptionCommand)
            {
                // Switch to the specified ink mode (Ink, GestureOnly or InkAndGesture).
                myWindow.ChangeInkModeOption((OptionId)e.Parameter);
            }
            else if (e.Command == ApplicationCommands.Undo)
            {
                myWindow.Undo(sender, e);
            }
            else if (e.Command == ApplicationCommands.Redo)
            {
                myWindow.Redo(sender, e);
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.MyWindow = ((InkCanvasEditingModes.SampleWindow)(target));
                return;

            case 2:
                this.MyHyperline = ((System.Windows.Documents.Hyperlink)(target));
                return;

            case 3:
                this.MyInkCanvas = ((System.Windows.Controls.InkCanvas)(target));
                return;
            }
            this._contentLoaded = true;
        }
示例#3
0
        /// <summary>
        /// A handler which handles the enabled status for a command.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnCanExecutedCommands(object sender, CanExecuteRoutedEventArgs e)
        {
            SampleWindow myWindow = (SampleWindow)sender;

            // By default, enable all commands.
            e.CanExecute = true;

            if (e.Command == SampleWindow.ClearCommand)
            {
                // Enable Clear command only if there is a non-empty stroke collection.
                e.CanExecute = myWindow.MyInkCanvas.Strokes.Count != 0;
            }
            else if (e.Command == ApplicationCommands.Undo)
            {
                // Enable only if there are items on the command stack
                e.CanExecute = myWindow._cmdStack.CanUndo;
            }
            else if (e.Command == ApplicationCommands.Redo)
            {
                // Enable only if there are items on the command stack
                e.CanExecute = myWindow._cmdStack.CanRedo;
            }
        }
示例#4
0
        /// <summary>
        /// EditingMode property change callback handler
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnEditingModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SampleWindow myWindow = (SampleWindow)d;

            myWindow.ChangeEditingMode((EditingModeId)e.NewValue);
        }