26

I have the following code to give a undocked floating AvalonDock window the ability to maximize:

class MaximizableDockableContent : AvalonDock.DockableContent
{
    public MaximizableDockableContent()
        : base()
    {
         base.StateChanged += MaximizableDockableContent_StateChanged;
    }

    private void MaximizableDockableContent_StateChanged(
        object sender, RoutedEventArgs e)
    {
        MaximizableDockableContent mdc = (MaximizableDockableContent)sender;
        if (mdc.State == DockableContentState.DockableWindow)
        {
            base.FloatingWindowSizeToContent = SizeToContent.WidthAndHeight;
            FloatingDockablePane fdp = (FloatingDockablePane)base.Parent;
            DockableFloatingWindow dfw = (DockableFloatingWindow)fdp.Parent;

            //dfw.WindowState = WindowState.Maximized;
            dfw.WindowStyle = WindowStyle.ThreeDBorderWindow;
            dfw.ResizeMode = ResizeMode.CanResize;

            //disable minimize button
            ControlBox.SetHasMinimizeButton(dfw, false);
        }
    }
}

How do I go about adding Aero Snap functionality to this?

sclv
  • 38,665
  • 7
  • 99
  • 204
Andreas
  • 3,843
  • 3
  • 40
  • 53
  • Snap is functionality implemented by the OS, not the Windows. You'd probably want to go about editing or deriving from DockingManager. – Jake Berger Jun 08 '11 at 23:46
  • 1
    the important class seems to be "WindowInteropWrapper.cs". I hope someone can point out the aero snap important lines. – Andreas Jun 15 '11 at 09:54
  • Do you want it to be able to snap to the whole screen or just a DockingManager? – Jake Berger Jun 15 '11 at 18:51
  • I want to be able to aero snap the (undocked floating) DockableContent to the edges of the whole screen, like it is possible with visual studio 2010. (For excample snap to the top edge it get maximized; snap to the right end left edge it it fills out half of the screen.) Thanks in advance. – Andreas Jun 15 '11 at 19:57
  • Each undocked floating panel in VS2010 is an OS Window; therefore, the reason it can snap is because the OS detects the Window and does its thing. This functionality should come by default for Windows 7. If you want this to happen in other OSs as well, you might want to start looking in DockingManager in the methods: IDropSurface.OnDragEnter, Drag(FloatingWindow, Point, Point). – Jake Berger Jun 20 '11 at 17:07
  • Many thanks for your help. I just want aero snap in windows 7. But unfortunately Win7 does not recognize my floating Avalondock content as a normal OS window and therefore does not snap it. It would be great if you could explain me which part of the code I have to edit. If you comment the line 483 (version1.3 from svn) in FloatingWindow.cs “wih.FilterMessage += new EventHandler(FilterMessage);” the dockable content aero snaps but unfortunately does not longer dock into the manager. – Andreas Jun 21 '11 at 08:18
  • It seems like the WindowInteropHelper Class causes the WindowMessages to be handled by the HookHandler exclusively and therefore the WindowMessages cannot trigger AeroSnap Events. – Andreas Jun 21 '11 at 08:18
  • In FloatingWindow.cs, lines 508, 510, 511; it seems to be exiting the switch if there's a WM_SIZE, WM_MOVE message. You might want to log these or check what's going on in there. – Jake Berger Jun 21 '11 at 17:36
  • thx for your fast answer. I will take a look at this. – Andreas Jun 22 '11 at 11:32

3 Answers3

1

you could run an external process, using runtime:

download nircmd.exe from: http://www.nirsoft.net/utils/nircmd.html and make sure it is in the same directory as the .class file or in the windows PATH environment variable

then use Runtime.exec() to run it several times:

Runtime r=Runtime.getRuntime();
r.exec("nircmd.exe sendkey lwin down");
r.exec("nircmd.exe sendkey "+direction+" press");
//change direction to "right" (for right side), "left" (for left side), or "up" (for full window).
r.exec("nircmd.exe sendkey lwin up");

note that this can throw an IOException, so a try/catch block might be necessary.

note:this assumes that the window is the active one.

Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65
1

anon said “Unfortunately is also disables, Windows + Up or Down arrow for Max./Min. the active Window.”

vIBIUS said “This also disables the Windows Key + Shift and Left/Right option!”

Kermonk said “unfortunately that also disables the “shake window to close all other windows” feature…”

Try this:

[HKEY_CURRENT_USER\Control Panel\Desktop]
"DockMoving"="0"

It disables the mouse action to maximise windows and snap windows to the side but not the keyboard shortcuts. It does not affect AeroPeak or AeroShake. It also does not affect ‘maximising a window in a verticle direction only’.

McDowell
  • 107,573
  • 31
  • 204
  • 267
1

For who is interested latest version of AvalonDock (version 2) natively supports floating window aero snap feature. AvalonDock 2.0 is still in beta, more info: http://avalondock.codeplex.com/ New features: http://avalondock.codeplex.com/wikipage?title=Version2Concept

adospace
  • 1,841
  • 1
  • 17
  • 15