如何在uwp中同时绘制两个笔画?

时间:2017-01-26 23:38:23

标签: uwp windows-10-universal inkcanvas win2d

我尝试在extendInt的{​​{1}}中绘制两行,但结果不如使用PointerMoveEvent

enter image description here enter image description here

是否可以使用Canvas来达到此目的?

InkCanvas

1 个答案:

答案 0 :(得分:1)

很抱歉迟到的回复。以下是一些可以帮助您的示例代码!

XAML:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <InkCanvas x:Name="testCanvas"/>
</Grid>

背后的代码

public MainPage()
    {
        this.InitializeComponent();
        testCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | 
            Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;
        testCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
    }
    private bool _strokeManipulating;
    private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
    {
        var strokes = args.Strokes;
        if (!_strokeManipulating)
        {
            _strokeManipulating = true;
            foreach (var s in strokes)
            {
                var n = s.Clone();
                //pass the required x,y translation
                var t = System.Numerics.Matrix3x2.CreateTranslation(5, 0);
                n.PointTransform = t;
                testCanvas.InkPresenter.StrokeContainer.AddStroke(n);
            }
            _strokeManipulating = false;
        }
    }

输出: enter image description here