CanvasImageSourceRecreate Method |
Namespace: Microsoft.Graphics.Canvas.UI.Xaml
public void Recreate( ICanvasResourceCreator value )
This recreates the image source associating it with the specified device. Any previous contents of the image source is discarded. CreateDrawingSession must be used to redraw the image.
This method should be called in response to the CompositionTarget.SurfaceContentsLost event or a device lost exception. One possible approach to handling this is:
void CompositionTarget_SurfaceContentsLost(object sender, object e) { surfaceContentsLost = true; UpdateImageSource(); } void UpdateImageSource() { var device = CanvasDevice.GetSharedDevice(); if (device != imageSource.Device || surfaceContentsLost) { imageSource.Recreate(device); surfaceContentsLost = false; } using (var ds = imageSource.CreateDrawingSession(clearColor)) { // ... } }