What event should I subscribe to for any change on an InkCanvas?

MG Bhadurudeen 626 Reputation points
2020-11-15T08:50:19.047+00:00

Hi, I want to detect if the user has drawn anything on an InkCanvas. I need this event to advise/intimate the user about saving the drawing before he leaves the page. So, what event should I subscribe to for any change on an InkCanvas?

<InkToolbar x:Name="inkToolbar" 
Height="90"
Tapped="InkToolbar_OnTapped"
VerticalAlignment="Top" 
HorizontalAlignment="Center"
TargetInkCanvas="{x:Bind inkCanvas}">

<InkCanvas x:Name="inkCanvas"
AnythingChanged="????"
Height="450" Width="800"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,996 Reputation points Microsoft Vendor
    2020-11-16T03:04:38.357+00:00

    Hello,

    Welcome to Microsoft Q&A!

    So, what event should I subscribe to for any change on an InkCanvas?

    You could take a look at the InkPresenter Class. It contains an event called InkPresenter.StrokesCollected Event which iccurs when one or more ink strokes are processed ("wet" to "dry") by the application thread.

    By default, an ink stroke is processed on a low-latency background thread and rendered wet as it is drawn. When the stroke is completed (pen or finger lifted, or mouse button released), the stroke is processed on the UI thread and rendered dry to the InkCanvas layer (above the application content). If the UI thread is busy, more than one ink stroke might be processed (collected) when the thread becomes available.

    So you could refer to the following code about how to subscribe to this event:

                InkPresenter inkPresenter = inkCanvas.InkPresenter;  
                inkPresenter.StrokesCollected += InkPresenter_StrokesCollected;  
    

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.