0

I am using the InkCanvas and InkToolBar in windows 10 build 14939 to capture user ink strokes.

I would like to do a custom button with Undo/Redo however I have trouble to create the following:

private static InkStroke CreateStroke(List<InkPoint> redoInkPoints) {
     var strokeBuilder = new InkStrokeBuilder();
     Matrix3x2 matr = new Matrix3x2();
     return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}

However visual studio complaints about the matr variable of

'Argment type 'System.Numerics.Matrix3x2' is not assignable to parameter type 'Windows.Foundation.Numerics.Matrix3x2'

even though I don't have anywhere in my code behind referencing the windows.foundation.numerics.matrix3x2.

Anyone got any idea or example on how I use the CreateStrokeFromInkPoints?

Bart
  • 9,925
  • 7
  • 47
  • 64
Jennifer
  • 15
  • 2

1 Answers1

0

According to your code, I think the problem here is that you've used wrong matrix in InkStrokeBuilder.CreateStrokeFromInkPoints method. While using Matrix3x2 matr = new Matrix3x2();, you are creating a zero matrix. It would collapse all your points into a singularity, which is not a valid value here. To fix this issue, you may use System.Numerics.Matrix3x2.Identity property which represents the identity matrix. And following is a simple sample:

XAML:

<StackPanel>
    <InkCanvas x:Name="inkCanvas" Width="500" Height="200" />
    <Button Click="Button_Click">Add a stroke</Button>
</StackPanel>

Code-behind:

private void Button_Click(object sender, RoutedEventArgs e)
{
    List<InkPoint> inkPoints = new List<InkPoint> { new InkPoint(new Point(10, 10), 0.5f), new InkPoint(new Point(100, 100), 0.5f) };

    InkStroke stroke = CreateStroke(inkPoints);

    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
}

private static InkStroke CreateStroke(List<InkPoint> redoInkPoints)
{
    var strokeBuilder = new InkStrokeBuilder();
    System.Numerics.Matrix3x2 matr = System.Numerics.Matrix3x2.Identity;
    return strokeBuilder.CreateStrokeFromInkPoints(redoInkPoints, matr);
}
Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • Thank you for your suggestion however with the changes, visual studio still complaints the matr variable of 'Argment type 'System.Numerics.Matrix3x2' is not assignable to parameter type 'Windows.Foundation.Numerics.Matrix3x2'. I am confused now as should the Matrix3x2 be type of System.Numerics (suggested in visual studio) or Windows.Foundation.Numerics (suggested from the msdn link above). – Jennifer Oct 04 '16 at 09:51
  • @Jennifer Have you tried my code with a new Blank App project? It works well in my side. If you still have error, then it may not in the code you've posted. It might be helpful if you can share a [mcve] that can reproduce your issue. – Jay Zuo Oct 04 '16 at 09:52
  • @Jennifer `Windows.Foundation.Numerics.Matrix3x2` is the base Windows Runtime type. If you are using C# for develop, then you should use `System.Numerics.Matrix3x2`. – Jay Zuo Oct 04 '16 at 09:59
  • Wow.... Thank you Jay - I have tried out with a new blank project even though the matr has the red squiggly line in the code behind but it complied fine. THANK YOU so much as I had already spent hours on that. – Jennifer Oct 04 '16 at 10:28