Hi Ashok,
Thanks for the sample, I was able to repro this scenario with native WPF controls that is effectively what Docking/MDI does. Add this to your sample XAML:
<Grid Width="200" DockPanel.Dock="Left">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentControl x:Name="container" />
<Button x:Name="adornmentTestButton" Grid.Row="1" Content="Click me" Click="adornmentTestButton_Click" />
</Grid>
Codebehind:
private Button button1 = new Button() { Content= "111" };
private Button button2 = new Button() { Content= "222" };
private void adornmentTestButton_Click(object sender, RoutedEventArgs e) {
if (container.Content == null) {
container.Content = button1;
container.UpdateLayout();
var adornerLayer = AdornerLayer.GetAdornerLayer(button1);
if (adornerLayer != null)
new ProcessingAdorner(button1, adornerLayer);
}
else if (container.Content == button1) {
container.Content = null;
container.Content = button2;
}
else {
container.Content = null;
container.Content = button1;
}
}
Click the button. The first time, your adorner is added. The second time you click the button, another object is swapped into the container (similar to our tab change). Then click the button a third time to restore the original content into the container that should still have an adorner. But the adorner is gone.
Unfortunately I'm not sure what we can do since it's out of our control and is something in Microsoft's code that seems to cause it. You may be better off making your own faux adornment layer but having a Grid as your root docking window content and then adding your processing adorner UI directly to that so it covers the other controls.