c# 关于InkCanvas面板,撤销的操作

来源:互联网 发布:wind数据库使用指南 编辑:程序博客网 时间:2024/05/22 03:23

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的时候,点击两次才能删除成功;

0 0
原创粉丝点击