尝试删除在inkcanvas中单击一下绘制的线

时间:2017-02-01 13:17:03

标签: xaml uwp

我正在尝试删除在inkcanvas中单击一下绘制的线条。 我的要求是,如果我在给定区域画一条线或任何图案, 它将擦除一次点击所绘制的所有线条,如果我绘制任何内容并单击“擦除”按钮,它将清除当前屏幕上绘制的所有线条。

的Xaml

<Grid x:Name="Bg_BigRect" Background="White"
       Width="310" Height="440"
       RelativePanel.Below="Bg_Rect"
       Margin="24,10,0,0">
    <Image x:Name="Trans_Tex" Source="WorkBook/T0.png"                              
           Margin="-10,0,0,20" 
           Width="310" Height="370"/>
        <InkCanvas x:Name="ink"/>
</Grid>

C#代码

public WorkBook()
{
    this.InitializeComponent();
    ink.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch;     

    // Set initial ink stroke attributes.
    InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
    drawingAttributes.Color = Windows.UI.Colors.Black;
    drawingAttributes.IgnorePressure = false;
    drawingAttributes.FitToCurve = true;
    ink.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
}

private void W_ClearTap(object sender, TappedRoutedEventArgs e)
{
    this.ink.InkPresenter.InputProcessingConfiguration.Mode = InkInputProcessingMode.Erasing;
}

参考图片

Screenshot of application

1 个答案:

答案 0 :(得分:0)

对于UWP应用,您可以使用InkStrokeContainer.Clear方法。例如:

ink.InkPresenter.StrokeContainer.Clear();