0

I'm struggling with new UWP InkCanvas for my apps.If you are familiar with the new InkCanvas in UWP, I would truly appreciate your help.

I have a UWP apps need to switching between InkCanvas and Canvas, which I wish to use InkCanvas for Drawing, Canvas for creating Contents such as RichEditbox, Image, etc...

My XAML is below

<Grid Margin="100,0,100,0" Background="White" x:Name="MainGrid" PointerMoved="MyCanvas_PointerMoved" PointerReleased="MyCanvas_PointerReleased" PointerPressed="MyCanvas_PointerPressed">
            <Canvas x:Name="MyCanvas" />
            <InkCanvas x:Name="inkCanvas" Canvas.ZIndex="0" />
            <!-- End "Step 2: Use InkCanvas to support basic inking" -->
</Grid>

I tried to make my Canvas ZIndex greater than InkCanvas by using

private void AppBarButton_Click(object sender, RoutedEventArgs e)
    {
        if(Canvas.GetZIndex(MyCanvas) > 1)
        {
            Canvas.SetZIndex(MyCanvas, 0);
        }
        else
        {
            Canvas.SetZIndex(MyCanvas, 5);
        }
    }

However I can't make my Canvas come to the front, the InkCanvas keep Capturing my stroke if I Draw on it instead.

Does anyone know how to switch the Canvas and InkCanvas in my Grid without changing the Visibility of my InkCanvas to Collapsed?

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
luvwinnie
  • 499
  • 1
  • 6
  • 23

1 Answers1

2

By default the Canvas background is empty (null), so it will not capture pointer input and will pass it through to the InkCanvas.

If you want to prevent this, you could set its Background to Transparent.

However, when you start putting some controls on the Canvas itself, they should capture the pen input and not let it through to the InkCanvas.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • 1
    Thanks for helping. It works miracle with my requirements. I added some Textbox to the canvas dynamically it just works fine when I switching the InkCanvas to the front by setting a new ZIndex. – luvwinnie Jan 19 '18 at 05:03
  • Great! Glad it helped :-) . Happy coding! – Martin Zikmund Jan 19 '18 at 05:16