从InkPresenter控件中删除所有墨迹

时间:2011-05-16 15:23:45

标签: .net silverlight

我正在使用InkPresenter控件并进行了设置,因此我可以使用此代码在其上绘制简单的黑线:

private Stroke newstroke;

public MainPage()
{
    InitializeComponent();
}

private void btnDownHandler(object sender, MouseButtonEventArgs e)
{
    inkP.CaptureMouse();
    newstroke = new Stroke();

    //Add stylus points via Getter-method, use inkP as argument.
    newstroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkP));

    //Add captured strokes to canvas.
    inkP.Strokes.Add(newstroke);
}

private void btnUpHandler(object sender, MouseButtonEventArgs e)
{
    //Set stroke object to NULL and stop capturing the mouse.
    newstroke = null;
    inkP.ReleaseMouseCapture();
}

private void mouseMoveHandler(object sender, MouseEventArgs e)
{
    //Check for NULL, see btnUpHandler
    if (newstroke != null) {
        //If not NULL, keep adding stylus points to the Stroke object.
        newstroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkP));
    }
}

我的问题是:我想实现一个按钮,我点击它,它会删除以前添加到InkPresenter的所有内容。

我已经尝试了inkP.Children.Clear();,但这不起作用。我试过了inkP.Strokes.Remove(newstroke)。也没用。

没有简单的功能可以删除所有

1 个答案:

答案 0 :(得分:1)

尝试inkP.Strokes.Clear();,而不是Children.Clear();