/// <summary> /// Change to the ink mode with an eraser setting. /// </summary> /// <param name="editingModeId"></param> private void ChangeToEraseMode(EditingModeId editingModeId) { switch (editingModeId) { case EditingModeId.PointEraser1: case EditingModeId.PointEraser2: case EditingModeId.PointEraser3: { // Change to the point erase mode StylusShape newSS = PointEraserShapeCollection[editingModeId - EditingModeId.PointEraser1]; ChangeToPointErase(newSS); break; } case EditingModeId.StrokeEraser: { // Change to the stroke erase mode EnsureEditingMode(InkCanvasEditingMode.EraseByStroke); break; } } // Update the readonly dependency property. SetValue(SampleWindow.CurrentEraserModePropertyKey, editingModeId); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null || values.Length == 0) { return(null); } for (int i = 0, count = values.Length; i < count; i++) { // Some source binding could have no value being set yet. If it's the case, return UnsetValue // to indicate no value produced by the converter. if (values[i] == DependencyProperty.UnsetValue) { return(DependencyProperty.UnsetValue); } } // Get the active pen or highlighter id EditingModeId currentActivePenOrHighlighterModeId = (EditingModeId)(values[0]); // Get the collection. ObservableCollection <DrawingAttributes> predefinedDrawingAttributes = values[1] as ObservableCollection <DrawingAttributes>; // Return the DrawingAttributes object. return(predefinedDrawingAttributes[(int)currentActivePenOrHighlighterModeId]); }
/// <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); } }
/// <summary> /// Change the editing mode. /// </summary> /// <param name="editingModeId"></param> private void ChangeEditingMode(EditingModeId editingModeId) { switch (editingModeId) { case EditingModeId.Pen1: case EditingModeId.Pen2: case EditingModeId.Pen3: case EditingModeId.Pen4: case EditingModeId.Pen5: case EditingModeId.Highlighter1: case EditingModeId.Highlighter2: case EditingModeId.Highlighter3: case EditingModeId.Highlighter4: case EditingModeId.Highlighter5: { // Change to the ink mode with the correct pen or highlighter setting. ChangeToInkMode(editingModeId); break; } case EditingModeId.PointEraser1: case EditingModeId.PointEraser2: case EditingModeId.PointEraser3: case EditingModeId.StrokeEraser: { // Change to the erase mode with the correct eraser. ChangeToEraseMode(editingModeId); break; } case EditingModeId.SelectionTool: { // Change to the select mode. EnsureEditingMode(InkCanvasEditingMode.Select); break; } case EditingModeId.None: { // Change to the none mode. EnsureEditingMode(InkCanvasEditingMode.None); break; } } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(null); } // Get the pre-defined DrawingAttributes collection ObservableCollection <DrawingAttributes> predefinedDrawingAttributes = value as ObservableCollection <DrawingAttributes>; // Get the pen/highlighter id associated to this control. EditingModeId expectedEditingModeId = (EditingModeId)parameter; if (expectedEditingModeId >= EditingModeId.Pen1 && expectedEditingModeId <= EditingModeId.Highlighter5) { // return the specified DrawingAttributes return(predefinedDrawingAttributes[(int)expectedEditingModeId]); } return(null); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(null); } // Get the bound property value. EditingModeId currentEditingModeId = (EditingModeId)value; // Get the id which the control expects EditingModeId expectedEditingModeId = (EditingModeId)parameter; if (expectedEditingModeId == currentEditingModeId) { // Returns true if the two values are same. return(true); } else if (expectedEditingModeId == EditingModeId.CurrentPen && (currentEditingModeId >= EditingModeId.Pen1 && currentEditingModeId <= EditingModeId.Pen5)) { // The pen toolbar button should be checked whenever any pen mode is active. return(true); } else if (expectedEditingModeId == EditingModeId.CurrentHighlighter && (currentEditingModeId >= EditingModeId.Highlighter1 && currentEditingModeId <= EditingModeId.Highlighter5)) { // The highlighter toolbar button should be checked whenever any highlighter mode is active. return(true); } else if (expectedEditingModeId == EditingModeId.CurrentEraser && ((currentEditingModeId >= EditingModeId.PointEraser1 && currentEditingModeId <= EditingModeId.PointEraser3) || currentEditingModeId == EditingModeId.StrokeEraser)) { // The eraser toolbar button should be checked whenever any eraser mode is active. return(true); } return(false); }
/// <summary> /// Change to the ink mode with a pen/highlighter setting. /// </summary> /// <param name="editingModeId"></param> private void ChangeToInkMode(EditingModeId editingModeId) { // Ensure the ink Mode based on the current option. InkCanvasEditingMode currentInkMode = _inkModeOptions[CurrentInkModeOption - OptionId.InkAndGesture]; EnsureEditingMode(currentInkMode); // Get the Drawing Attributes which is associated to the pen/highlighter setting. // Then update the InkCanvas' DefaultDrawingAttributes property. DrawingAttributes da = DrawingAttributesCollection[editingModeId - EditingModeId.Pen1]; MyInkCanvas.DefaultDrawingAttributes = da; // Update the read-only DependencyProperties so that the UI can react to the change correspondingly. if (editingModeId >= EditingModeId.Pen1 && editingModeId <= EditingModeId.Pen5) { SetValue(SampleWindow.CurrentPenModePropertyKey, editingModeId); } else if (editingModeId >= EditingModeId.Highlighter1 && editingModeId <= EditingModeId.Highlighter5) { SetValue(SampleWindow.CurrentHighlighterModePropertyKey, editingModeId); } }