Click or drag to resize
CanvasImageSourceRecreate Method
Recreates the underlying image source.

Namespace:  Microsoft.Graphics.Canvas.UI.Xaml
Assembly:  Microsoft.Graphics.Canvas (in Microsoft.Graphics.Canvas.dll) Version: 0.0.0.0
Syntax
C#
public void Recreate(
	ICanvasResourceCreator value
)

Parameters

value
Type: Microsoft.Graphics.CanvasICanvasResourceCreator
Remarks

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))
    {
        // ...
    }
}
See ImageSourceUpdateRegion.xaml.cs in ExampleGallery for a more complete example.

See Also