This project is read-only.

[Version 2.0] LayoutAnchorablePane and Menus

Jan 9, 2013 at 7: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.

http://blogs.msdn.com/b/visualstudio/archive/2010/03/09/wpf-in-visual-studio-2010-part-3-focus-and-activation.aspx

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

 

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

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

Thanks!

 

May 9, 2014 at 3:51 PM
Hi,
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 9:10 AM
Edited Dec 17, 2016 at 10: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

EDIT2:
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;
      return;
  }
  else
  {
      base.OnPreviewGotKeyboardFocus(e);
  }
}