public sealed partial class MainPage : Page
this.InitializeComponent();
var canvas = new CanvasAnimatedControl();
Grid.Children.Add(canvas);
canvas.Draw += Canvas_Draw;
protected override void OnPointerMoved(PointerRoutedEventArgs e)
_move = e.GetCurrentPoint(Grid).Position;
private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
var cl = DrawRectangle(sender);
using (var ds = args.DrawingSession)
ds.DrawImage(cl, new Vector2(10, 10));
private CanvasCommandList DrawRectangle(ICanvasResourceCreator sender)
Rect rect1 = new Rect(50, 50, 10, 10);
Rect rect2 = new Rect(_move, new Size(10, 10));
var cl = new CanvasCommandList(sender);
using (var ds = cl.CreateDrawingSession())
ds.DrawRectangle(rect1, Colors.IndianRed);
ds.DrawRectangle(rect2, new Color()
if (rect1.Left <= rect2.Left && rect1.Top <= rect2.Top)
VerpallWayhi(rect1, rect2, ds);
else if (rect2.Left < rect1.Left && rect2.Top < rect1.Top)
VerpallWayhi(rect2, rect1, ds);
else if (rect1.Left <= rect2.Left && rect1.Bottom >= rect2.Bottom)
Stoutiheagea(rect1, rect2, ds);
else if (rect2.Left < rect1.Left && rect2.Bottom > rect1.Bottom)
Stoutiheagea(rect2, rect1, ds);
private void Stoutiheagea(Rect rect1, Rect rect2, CanvasDrawingSession ds)
var canvasPathBuilder = new CanvasPathBuilder(ds.Device);
canvasPathBuilder.BeginFigure((float) rect1.Left, (float) rect1.Top);
canvasPathBuilder.AddLine((float) rect2.Left, (float) rect2.Top);
canvasPathBuilder.AddLine((float) rect2.Right, (float) rect2.Top);
canvasPathBuilder.AddLine((float) rect2.Right, (float) rect2.Bottom);
canvasPathBuilder.AddLine((float) rect1.Right, (float) rect1.Bottom);
canvasPathBuilder.AddLine((float) rect1.Left, (float) rect1.Bottom);
canvasPathBuilder.EndFigure(CanvasFigureLoop.Closed);
var geometry = CanvasGeometry.CreatePath(canvasPathBuilder);
ds.DrawGeometry(geometry, new Color()
canvasPathBuilder.Dispose();
private void VerpallWayhi(Rect rect1, Rect rect2, CanvasDrawingSession ds)
var canvasPathBuilder = new CanvasPathBuilder(ds.Device);
canvasPathBuilder.BeginFigure((float) rect1.Left, (float) rect1.Top);
canvasPathBuilder.AddLine((float) rect1.Right, (float) rect1.Top);
canvasPathBuilder.AddLine((float) rect2.Right, (float) rect2.Top);
canvasPathBuilder.AddLine((float) rect2.Right, (float) rect2.Bottom);
canvasPathBuilder.AddLine((float) rect2.Left, (float) rect2.Bottom);
canvasPathBuilder.AddLine((float) rect1.Left, (float) rect1.Bottom);
canvasPathBuilder.EndFigure(CanvasFigureLoop.Closed);
var geometry = CanvasGeometry.CreatePath(canvasPathBuilder);
ds.DrawGeometry(geometry, new Color()
canvasPathBuilder.Dispose();