private AdornerLayer CreateLayer(UIElement gameSideElement) { var canvas = GetAdornerCanvas(); if (canvas == null) { return(null); } var font = Controller.DefaultFont; var layer = new AdornerLayer(gameSideElement); // Create margins adorners layer.Add(new MarginAdorner(this, gameSideElement, MarginEdge.Left, font), true); layer.Add(new MarginAdorner(this, gameSideElement, MarginEdge.Right, font), true); layer.Add(new MarginAdorner(this, gameSideElement, MarginEdge.Top, font), true); layer.Add(new MarginAdorner(this, gameSideElement, MarginEdge.Bottom, font), true); // Create highlight adorner layer.SetHighlightAdorner(new HighlightAdorner(this, gameSideElement)); // Create move adorner layer.Add(new MoveAdorner(this, gameSideElement)); // Create sizing adorners layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.TopLeft)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.Top)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.TopRight)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.Right)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.BottomRight)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.Bottom)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.BottomLeft)); layer.Add(new SizingAdorner(this, gameSideElement, ResizingDirection.Left)); // Add to collection and canvas adornerLayers.Add(gameSideElement.Id, layer); canvas.Children.Add(layer.Visual); // Make sure adorners will be rendered correctly the next time layer.Invalidate(); return(layer); }