次の方法で共有


More on AERO Shake and WPF

A few follow-up questions (and answers) from this post on Aero shake in WPF Windowless apps .

The code I posted does not work if your WPF WindowStyle=None window is maximized. Why is that?

The shell detects the shake based on Windows movement, and when a window is maximized, it can not be dragged. This is a behavior defined by the shell :(

Can’t you just ‘detect’ mouse move events and identify the shake gesture and then call the Shell’s API to do the shake?

Unfortunately not.  The shell does not publicly expose APIs to implement the shake behavior – which is minimizing all windows except for the one that is being shaken-.

Are we out of luck then to get Aero Shake on a ‘full screen’ app?

I think that simulating shake (several posts on the web that do that) is not ideal.  Those posts do it to bring Shake to earlier versions of Windows that do not have it.   What I advised the person that did it was to not maximize their Window.  You can detect the available screen real-estate and size to that.

 this.Width = SystemParameters.FullPrimaryScreenWidth;
this.Height = SystemParameters.FullPrimaryScreenHeight
          + SystemParameters.CaptionHeight;
this.ResizeMode = ResizeMode.NoResize; 

To most users (who are not looking to shake),  the window will still look like it is maximized. No difference.

To a user that is looking to shake, the window can be moved (and shaked).  The mere idea of ‘shaking’ a full screen window is not very common, but in this case the app was partially transparent so it did need it.  All I did was allow the shake again using DragMove, and then resetting the position of the window back to 0,0 after the shake. 

 

 private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
            this.Left = 0;
            this.Top = 0; 

        }

I am not claiming this is a best practice, but it worked good enough for my expectations.  If you want to see the code and decide if it works for your scenario, you can download a sample app from here.

Why the emphasis on WindowStyle=None, does Aero Shake work on WPF apps with standard windows?   

Aero Shake works fine with standard WPF windows;  no changes are needed to your WPF apps.  It is the windowless apps that needed the few lines I have shared in these posts. 

At last, if you do not know what Aero Shake is, you can watch shake in action in this 15 seconds video.