luvwinnie
luvwinnie

Reputation: 509

How to switching between InkCanvas and Canvas in UWP

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?

Upvotes: 0

Views: 648

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39072

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.

Upvotes: 2

Related Questions