[Version 2.0] LayoutAnchorablePane and Menus

Jan 9, 2013 at 6:14 PM

I'm seeing an issue when switching between docked LayoutAnchorables that contain WPF Menu controls.  The exception actually occurs in WPF libraries and states that the argument 'menuSite' is null, apparently when trying to set the MenuMode.  The only thing I could find that really referenced MenuMode is the link below, which makes me think the cause may have something to do with the way AvalonDock is handling focus.


This is easily reproducible in the TestApp, just replace 'toolWindow2' with the following.


<avalonDock:LayoutAnchorable ContentId="toolWindow2" Title="Tool Window 2">
    <Menu IsMainMenu="False">
      <MenuItem Header="Menu Item 1" />
    <TextBlock Text="{Binding FocusedElement}"/>

I did not see this issue with version 1.3 and it doesn't seem to happen in other situations (ie. LayoutDocumentPane).



May 9, 2014 at 2:51 PM
I was facing this issue too and was driving me crazy because I couldn't find the reason.

Moreover, I can give more details. If you have 2 LayoutAnchorable with a menu (doesn't seem to happen with buttons, charts etc) if you don't change the tab and you put the two LayoutAnchorable side by side, it won't throw any errors. But if you "merge" them again and you change the tab it will throw that error.

I hope I am clear enough.
Dec 17, 2016 at 8:10 AM
Edited Dec 17, 2016 at 9:50 PM
This is broken and it is unclear how to fix this. The stack trace is purely windows/.net libraries, and are useless for debugging.

EDIT: null MenuSite bug resolved by removing call to base.OnPreviewGotKeyboardFocus() in OnPreviewGotKeyboardFocus() in DockingManager.cs, and setting e.Handled = true

Some unintended consequences of simply handling all calls, instead I did this in DockingManager.cs and it worked:
protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
  Trace.WriteLine(string.Format("DockingManager.OnPreviewGotKeyboardFocus({0})", e.NewFocus));
  if (e.NewFocus is TabItem)
      e.Handled = true;