-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Windows 11 "Snap Layout" to the custom title bar (WindowChrome) #4825
Comments
Ref #4749 |
Does anyone know if there is an API to trigger the new snap layout "menu"? |
It is not a system command. If you have a custom maximize button, it is your job to tell that to the OS by responding I think there is an opportunity for API improvement to simplify this task through an attached |
This would be helpful for Windows Terminal, as well as other WinUI 3 apps. |
@miloush While returning
|
@batzen I guess you can still handle the mouse over, however yeah I will give you that the system-rendered button on click is sad; feels like a bug in the shell. |
@miloush The events aren't even raised when the caption button |
We also have been digging into this issue of trying to show the Snap Layout Menu in a WPF app that uses our custom WindowChrome, where we render all custom title bar buttons. We've run into the same issues when returning HTMAXBUTTON from WM_NCHITTEST as described above, where WPF no longer receives any pointer input (due to HTCLIENT not being returned), and clicking our custom button renders a classic Win32 maximize button. We really need some other API than responding to WM_NCHITTEST to get this working for those of us who have powerful custom window chromes and need the WPF elements in those chromes to remain responsive. |
FYI: The WindowChromeBehavior from ControlzEx will provide a solution for this problem during Hacktoberfest. |
@batzen Are you able to share with us a copy of the test app so we can get to the bottom of this? |
I can share a link to the branch in ControlzEx as soon as i pushed the changes. |
@mevey You can grab the code from https://github.com/ControlzEx/ControlzEx/tree/features/Win11Support Please note that it's still a WIP and i haven't yet implemented support for rounded corners, but the snap menu on the maximize button works without all the negative side effects everyone observed. |
Thank you @batzen, this is extremely helpful as we try to understand root cause. |
We also have worked the past week on Windows 11 features in our own WindowChrome and have managed to get the snap layout menu showing without the two negative side effects we found in our first attempt. Our changes can be summarized as:
While the above sounds relatively simple, it really isn't and ended up being a lot more work than we'd hoped. We've had to hack things in to handle the edge cases like proper hover state display on the button when the menu is open. It would be nice if the system could notify the window somehow when the snap layout menu was opening/closing so we could alter our hover state on our Maximize button. Right now it seems no Windows Win32 messages are sent to the window once the snap layout menu opens. It's difficult to know if the mouse then moves over that menu or not. |
@billhenn Point 3 is the reason why I created https://github.com/ControlzEx/ControlzEx/blob/features/Win11Support/src/ControlzEx/Behaviors/WindowChrome/NonClientControlManager.cs |
Yes, that is the one of the most difficult things we've had to attempt to work around. It would be nice if there was a way to manually request the snap layout menu show so we could avoid the entire hacky non-client piece of things. If our WPF Button could detect a hover scenario on itself, then we could simply call some Windows API (which probably doesn't currently exist) to request the snap layout menu at a certain screen coordinate and be done with it. |
Hey folks, Just letting you know that we are still working on this issue internally and will have a response for you soon. We appreciate your patience. |
@mevey any updates on this? |
For anyone interested: ControlzEx/ControlzEx#151 |
Hi @batzen Your example was very complex (at least for me) I used another code. I was able to show SnapLayout But I see the problems you mentioned earlier You seem to have solved these problems, Can you help me solve these problems?
|
Hi, @ghost1372 . i have checked your code in my c# wpf application ,i am getting compile time error . |
|
Hey @gurpreet-wpf thanks for those details. However it is not clear how this should be implemented and what is the actual change? Do you have working example of Window with custom title bar supporting Snap Layout menu? |
Hi @kalin-todorov , the default implementation of this feature got fixed by Windows team. We need to work on Custom Chrome bar to have this ability. |
Hi @gurpreet-wpf, so is there any new API that will allow us to show manually the menu? |
Hi again @gurpreet-wpf any updates on this item? |
@kalin-todorov - Apologies for the delayed response. However, we're planning to incorporate this feature in upcoming releases. |
@pchaurasia14 thanks for the reply! However, I'm more interested in the Windows API that will allow custom title bar to be implemented in a correct manner. So, is there any new Windows API that can be used to open up the snap UI manually? |
I am also interested in this Win32/WinRT API. Visual Studio is built with WPF, has custom titlebar buttons AND the Snap Layout panel is working just fine. How did they do it? |
The requirement to get the snap menu is to return the proper hittest result when Windows asks your app. |
I got this half working using examples people have provided. If the window is maximized, the snap layout popup appears when hovering over the "Restore" button. But if the window is not maximized, it doesn't ever show, even though I am still returning HTMAXBUTTON. Has anyone else seen this issue? |
I've experimented that if you have a custom chrome but WindowStyle is not None the snap popup is only displayed if you return HTMAXBUTTON where the system button would be. That means, if the title bar buttons are smaller/larger/taller than the system ones it will only work on part of the maximize button. It works properly if WindowStyle=None, but that requires more code for fixing maximization, flicker and other stuff. |
@manfromarce you were right. Changing my WindowStyle to None made it start working when the window is not maximized. But unfortunately I don't want to use WindowStyle=None because of what you lose when you do. Hopefully this is a bug that they can fix. (@gurpreet-wpf) |
@Gilfoylex Good, looking forward to your https://github.com/Gilfoylex/WPFUiBase |
Hi! We're developing a library that enables us to use modern styles and components in WPF applications. https://github.com/InkoreStudios/UI.WPF.Modern Thanks! |
It would be nice to have this be possible. The default title bar in WPF gives off big Windows 7 vibes and seems to have been completely ignored by Microsoft. |
@damien-c-d The default title bar in WPF is the default Windows title bar and supports snap layout. But when using a custom window chrome there is no snap layout and a plethora of other issues caused by it. |
The default title bar is rubbish and the offers very little options in the way of customisation and theme support. That's why an overwhelming majority of UI libraries have customised the window chrome. You're completely correct, using a custom window chrome does have those problems. Seems like a design issue to me. So really that's the only out of the box options we have in WPF. Pretty poor in my opinion. Problem is some of the most widely used UI libraries are waiting for this to be implemented: https://www.syncfusion.com/feedback/36976/show-snap-layout-option-while-hovering-the-maximize-button https://feedback.telerik.com/wpf/1559117-radribbonwindow-don-t-support-window-11-snap-layout-feature Not the only place I've seen the issue referenced either: It would be nice to have some accountability on this. |
Originally posted by @mevey in #4825 (comment) I'm still curious about this feature, are there any further updates and is it planned to be progressed? It would make apps feel a lot more professional, right now mine feels "homemade" which isn't what I'm going for:) |
I'd rather stick with the default titlebar if WPF would take care of most boilerplate code. E.g. query the Windows theme settings and to set |
ControlzEx WindowChromeBehavior works like a charm, fully supporting snap layout. I have also created a fully custom window titlebar example based on ControlzEx. code example |
After implementing Snap Layout, styles for the button do not work. For VisualStateManager.GoToState(btnMaximizeRestore, "MouseOver", true);
VisualStateManager.GoToState(btnMaximizeRestore, "Normal", true); |
@Yari27 I'm sorry, but with limited information, I can't find the answer. Could you attach the solution folder? |
It doesn't work because once you return hittest results like maximize the controls no longer receive mouse over events. |
@batzen thx, attached property work great. |
I created a library WPF Suite including this feature,process the WM_NCHITTEST message, set the IsMouseOver and IsPressed properties of the control, and correctly trigger the Button's Click event, execute its Command。
Here is the document and sample code for using it。 |
If anyone is interested, flutter needs a way to Snap Layout work when title bar is customized too: |
@augustresende I believe Electron supports this feature. It'd be worth checking out how they did it. |
As Windows 11 introduce Snap Layout when we hover on Restore/Maximize caption button, I want to have this feature on my custom title bar using
WindowChrome
.The current
SystemCommands
class does not have it:Custom Title bar
Default Title bar
The text was updated successfully, but these errors were encountered: