1. 定义标签
<CustomControls:WpfImageButton x:Name="Erase" Cursor="Hand" ImageHeight="60" ImageWidth="60" Margin="8,3,8,3"
Click="undo_Click"/>
2. 定义事件:
Stack<StrokeCollection> tempList = new Stack<StrokeCollection>();
private void undo_Click(object sender, RoutedEventArgs e)
{
if(tempList .Count > 0)
{
inkCanvas1.Strokes.Remove(tempList .Pop());
}
}
3. 初始化组建的时候,定义监听事件:
inkCanvas.Strokes.StrokesChanged += Strokes_StrokesChanged;
private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
{
if(e.Added.Count > 0)
{
tempList .Push(e.Added);
}
}
注意:监听事件的时候必须添加if条件,要不然在undo的时候,点击两次才能删除成功;