adornerlayer

AdornerLayer.GetAdornerLayer() return NULL for all controls in a Panel

别来无恙 提交于 2019-12-04 13:12:27
I'm facing the fact that i cannot understand Well how AdornerLayer is added for UIElements. I have such a situation: I have a WPF Form which is built with 3 controls: A Grid on which are 1 Button and 1 TextBox . In my System, when I click to open this Form, all 3 elements have AdornerLayer not null . var controls = _frameworkElementProvider.GetUIElements(Content); var controlsWithAddorner = new List<FrameworkElement>(); foreach (var control in controls) { var adornerLayer = AdornerLayer.GetAdornerLayer(control); if (adornerLayer != null) { controlsWithAddorner.Add(control); } } The collection

GetAdornerLayer mysteriously returning null

会有一股神秘感。 提交于 2019-12-01 03:21:20
I've been using the same bit of code for several versions of my app with no problems, but I'm now mysteriously receiving NullRerefenceException s with the following: this.Loaded += delegate { deleteBrush = new DeleteBrushAdorner( background ); AdornerLayer al = AdornerLayer.GetAdornerLayer( background ); al.Add( deleteBrush ); // null ref here?? }; background is just a Border element. My two thoughts on what could be causing it are a) switching to .NET 4.0, and b) placing instances of the above element (which is a UserControl ) in an ItemsControl . Oddly this doesn't happen all the time, and