I have a problem with
AdornerLayer AdornerLayer = AdornerLayer.GetAdornerLayer (layout);
This method returns always null.
What am I doing wrong?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Layout layout = new Layout();
layout.Background = Brushes.White;
layout.ClipToBounds = true;
layout.SnapsToDevicePixels = true;
layout.Width = 4965; layout.Height = 3515;
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(layout);
adornerLayer.Add(new LayoutAdorner(layout));
}
}
public class Layout : Canvas
{
public Visual GetVisualChildAtPoint(Point point)
{
return VisualTreeHelper.HitTest(this, point).VisualHit as Visual;
}
}
public class LayoutAdorner : Adorner
{
public LayoutAdorner(UIElement adornedElement) : base(adornedElement) { }
protected override void OnRender(DrawingContext drawingContext)
{
}
}
The AdornerLayer
for the Window won't be created until the window is actually loaded and the handle is created.
Instead of placing this in the constructor, you may need to delay, and add the adorner when the window is loaded instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With