/ win2d

How to solve device lost of Win2D's CanvasControl

In some case, you may find out that when you call CanvasControl's Invalidate() method, the Draw event will not be raised. Now if you watch the variable of CanvasControl you can find the Device property is throwing an ArgumentException and of course the Draw event will not be raised.

The source of this issue hasn't been found, but I do have a solution(or call it workaround), this workaround will be apply if you have the similar need:

You don't want to use CanvasControl to draw sth at the first time, you want to draw it later after some logical operation.

In my case, my page will receive an image and then blur it.

Here is the workaround:

  • First add the attribute of CanvasControl in XAML:


  • When you are ready to draw sth, find it and prepare resource then call Invalidate():

//do sth