I have to deal with the fact that I canβt understand how much AdornerLayer has been added for UIElements.
I have this situation:
I have a WPF form that is built with three controls: A Grid on which there is 1 Button and 1 Text Box . 
On 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 controlsWithAddorner collection contains all of my 3 controls.
The GetUIElements(FrameworkElement parent) method returns IEnumerable<FrameworkElement> , which contains all the controls in the panel .
I have this functionality: Update the form constructor . What recreates haml for this Form.
After this Update , I check the list of controls for AdornerLayer. For all controls, AdornerLayer is NULL.
The problem is here, I canβt understand where the AdornerLayer is lost? Do I have to take care to add them for each UIElement when I update the form constructor?
Please advise me some suggestions.
Thanks!
EDIT: I will show the whole solution if others encounter such problems :)
The mission is this: when there is a SelectedControl constructor in the designer, save it even if RefreshDesigner is running.

The RefreshDesigner function recreates xaml for the entire form.
First : the xaml of the form is updated using the ParseXaml() method from XamlProvider
// in XamlProvider class public Panel ParseXaml(string xaml) { var regex = new Regex("<Grid "); const int first = 1; xaml = Regex.Replace(xaml, @"xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""", string.Empty); xaml = Regex.Replace(xaml, @"xml:space=""preserve""", string.Empty); //... xaml = Regex.Replace(xaml, "<BindingGroup .*/>", string.Empty); var content = (Panel)XamlReader.Parse(xaml); return content; }
Secondly: Content.UpdateLayout(); Ensures that all visual child elements of this element are correctly updated for the layout. Official MSDN Source
After that, all elements have AdornelLayer not Null, and I can set Adorner Border for the pre-selected control in the designer.