void DrawToImageSource(CanvasDrawingSession canvasControlDrawingSession) { // XAML doesn't support nested image source drawing sessions, so we must close // the main CanvasControl one before drawing to a different CanvasImageSource. canvasControlDrawingSession.Dispose(); using (var ds = imageSource.CreateDrawingSession(Colors.Transparent)) { DrawToOutput(mainDeviceResources, ds); } }