Код: Выделить всё
private CanvasRenderTarget offscreen;
private CanvasDevice device = CanvasDevice.GetSharedDevice();
private DispatcherTimer Timer;
< /code>
В конструкторе: < /p>
offscreen = new CanvasRenderTarget(device, 300, 255, 96);
Timer = new DispatcherTimer();
Timer.Interval = TimeSpan.FromMilliseconds(refreshRate);
Timer.Tick += Timer_Tick;
Timer.Start();
< /code>
Работать в событии Timer_tick: < /p>
private void Timer_Tick(object? sender, object e)
{
using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
{
// Draw rectangle
ds.FillRectangle(10, 10, 100, 100, Colors.Red);
// Source rect to be copied
Rect sourceRegion = new Rect(10, 10, 50, 50);
// Define the destination point on the current canvas
Vector2 destinationPoint = new Vector2(150, 150);
// Copy the specified region from the source to the destination
**ds.DrawImage(offscreen, destinationPoint, sourceRegion); // Unhandled error**
}
if (this.waterfallCanvas != null) this.waterfallCanvas.Invalidate();
}
private void waterfallCanvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
if (offscreen != null) args.DrawingSession.DrawImage(offscreen, 0, 0);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ingsession