InkCanvas橡皮擦

时间:2011-03-30 05:37:04

标签: wpf silverlight mvvm inkcanvas

我的草图为InkCanvas;我想改变橡皮擦的大小,所以我写了:

Private Sub Sketchpad_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs) Handles Sketchpad.KeyDown

If e.Key = Key.OemMinus Then

' Decrease size of Eraser to 5*5 

Sketchpad.EraserShape = New RectangleStylusShape(5, 5)

End If

If e.Key = Key.OemPlus Then

' Increase size of Eraser to 50*50 

Sketchpad.EraserShape = New RectangleStylusShape(50, 50)

End If

If e.Key = Key.I Then
' Change editing mode to Ink
Sketchpad.EditingMode = InkCanvasEditingMode.Ink

End If

If e.Key = Key.E Then
' Change editing mode to Eraser
Sketchpad.EditingMode = InkCanvasEditingMode.EraseByPoint

End If

End Sub

试试这个:

  1. 按e选择橡皮擦,橡皮擦手写笔将出现矩形
  2. 按+符号增加尺寸,您将看不到任何更改。为什么?
  3. 现在您按i更改编辑模式,将显示墨水提示。
  4. 再次按e重新开关到橡皮擦。你会看到橡皮擦的形状已经改变了。
  5. 为什么不按+号后?

1 个答案:

答案 0 :(得分:2)

来自help

“如果更改EraserShape,则在下一个EditingMode更改之前,InkCanvas上呈现的光标不会更新。”

我测试了以下代码并且工作正常:

if (e.Key == Key.OemMinus)
{
    ink.EraserShape = new RectangleStylusShape(5, 5);
    var editMode = ink.EditingMode;
    ink.EditingMode = InkCanvasEditingMode.None;
    ink.EditingMode = editMode;
}
if (e.Key == Key.OemPlus)
{
    ink.EraserShape = new RectangleStylusShape(50, 50);
    var editMode = ink.EditingMode;
    ink.EditingMode = InkCanvasEditingMode.None;
    ink.EditingMode = editMode;
}