Gaoyifei1011 / GetStoreApp

离线下载 Microsoft Store 商店应用
MIT License
779 stars 29 forks source link

Discussion: How you made a custom titlebar context menu? #13

Closed Alloyd031 closed 4 months ago

Alloyd031 commented 5 months ago

I was browsing the code and got interested, how you made a custom titlebar context menu?

Gaoyifei1011 commented 5 months ago

您可以参考以下内容 You can refer to the following

image

这是我自定义标题栏右键菜单的菜单浮出控件的内容 This is the content of my custom title bar right-click menu of the menu surface control https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/Views/Windows/MainWindow.xaml#L72

使用自定义窗口标题栏时,这时 Window.ExtendsContentIntoTitlebar = true,需要做出下面所列出的操作。 Using a custom Window title bar, at this time Window. ExtendsContentIntoTitlebar = true, need to make the operation of the listed below. https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/Views/Windows/MainWindow.xaml.cs#L169 寻找非工作区(窗口类:InputNonClientPointerSource 类)的窗口句柄,并为其添加窗口过程。 Looking for non-work area (window class: InputNonClientPointerSource class) the window handle, and to add the window procedure.

处理非工作区窗口消息,尤其是默认窗口右键菜单的消息(WM_NCRBUTTONUP) Handles non-workspace window messages, especially messages from the default window right-click menu (WM_NCRBUTTONUP) https://github.com/Gaoyifei1011/GetStoreApp/blob/991978b158ea4235b053721dc98c413775b8cfc3/GetStoreApp/Views/Windows/MainWindow.xaml.cs#L939

Handle window messages when the application window is in focus by pressing Alt + Space on the keyboard Add window procedures for application window handles to handle corresponding window messages 处理应用窗口处于焦点状态时,键盘按下 Alt + Space 的窗口消息 为应用窗口句柄添加窗口过程,处理相应的窗口消息 https://github.com/Gaoyifei1011/GetStoreApp/blob/991978b158ea4235b053721dc98c413775b8cfc3/GetStoreApp/Views/Windows/MainWindow.xaml.cs#L165 https://github.com/Gaoyifei1011/GetStoreApp/blob/991978b158ea4235b053721dc98c413775b8cfc3/GetStoreApp/Views/Windows/MainWindow.xaml.cs#L910

我使用的自定义的窗口右键菜单浮出控件的样式(您可以自己定制所需要外观的窗口右键菜单) I used a custom window right-click menu surface control style (you can customize the desired look of the window right-click menu) https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/Styles/MenuFlyout.xaml

Gaoyifei1011 commented 5 months ago

I was browsing the code and got interested, how you made a custom titlebar context menu?

If there are no further questions, the discussion will close in a few hours, thank you for asking

Alloyd031 commented 5 months ago

I wanted to implement that in my app, but the code gives me a lot of errors, so can you make a tutorial of something?

Gaoyifei1011 commented 5 months ago

I wanted to implement that in my app, but the code gives me a lot of errors, so can you make a tutorial of something?

Yeah, all right. Only these two days I am busy with the midterm defense of my master's thesis, and I have no time for the moment. I try to write a blank template tutorial on Sundays if I can. At present, you encounter any mistakes, first you can send the reason or screenshot of the error, I can solve your problems

Gaoyifei1011 commented 4 months ago

I wanted to implement that in my app, but the code gives me a lot of errors, so can you make a tutorial of something?

Updated Demo Repository URL:https://github.com/Gaoyifei1011/WinUI3WindowMenuStyle

已更新 Demo 仓库地址:https://github.com/Gaoyifei1011/WinUI3WindowMenuStyle