I am trying to achieve a VS style MainWindow + docking content host on secondary monitors. Avalon dock does the job gracefully. Until minimizing the window, that is.
Upon restore, the maximized 'docking host"(LayoutAnchorablePane) resets it's size and location to the pre-maximizing ones.
This is because when maximizing an avalon dock LayoutAnchorablePane, the Property Changed event doesn't fire. Also, the floating width property doesn't get updated.
This is why my first try __
public Window3()
{
InitializeComponent();
// Intercept the minimize event and cancel it.
this.SourceInitialized += OnSourceInitialized;
}
private void OnSourceInitialized(object sender, EventArgs e)
{
var source = (HwndSource)PresentationSource.FromVisual(this);
if (source != null) source.AddHook(HandleMessages);
}
//These store the location and size of Left - the Layout Anchorable to be placed on a sec monitor
private Point _location;
private Size _size;
private IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg != 0x0112 || ((int) wParam & 0xFFF0) != 0xF020) return IntPtr.Zero;
//This means a minimize for the Main Window. Cancel it.
handled = true;
//Get the sec monitor anchorable size and location
_location = new Point(Left.FloatingLeft, Left.FloatingTop);
_size = new Size(Left.FloatingWidth, Left.FloatingHeight);
//finally minimize the window
WindowState = WindowState.Minimized;
return IntPtr.Zero;
}
private void Window3_OnStateChanged(object sender, EventArgs e)
{
//Restore the width and location for the sec monitor anchorable
// Fail. Cry. Cry a lot...
if (WindowState == WindowState.Maximized)
{
Left.FloatingLeft = _location.X;
Left.FloatingTop = _location.Y;
Left.FloatingWidth = _size.Width;
Left.FloatingHeight = _size.Height;
}
}
__ doesn't work.
These maximize / restore events are unreachable. They're stored in Controls/Shell/SystemCommands.cs
public static void MaximizeWindow(Window window)
{
Verify.IsNotNull(window, "window");
_PostSystemCommand(window, SC.MAXIMIZE);
}
private static void _PostSystemCommand(Window window, SC command)
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero || !NativeMethods.IsWindow(hwnd))
{
return;
}
NativeMethods.PostMessage(hwnd, WM.SYSCOMMAND, new IntPtr((int)command), IntPtr.Zero);
}
I've read some tips on avalondock's codeplex discussion but I think they applied to previous versions and were no longer valid.
I am thinking of using user32 GetWindowRect and SetWindowPos to get the location and size on minimize and restore it on maximize.
But, i simply have no ideea how to get the handle for the floating anchorables.
Any suggestion , on the floater handle or otherwise, will be greatly appreciated. Thank you for your time.
LayoutFloatingWindowControl.OnStateChanged(EventArgs)
is called on when I maximize withWindowState==Maximized
, and again on restore from minimized withWindowState==Normal
, but don't know where to go from there. – clcto