When I first came into contact with WPF, I made a custom form to change the title bar style and support dragging and zooming. The two windows methods are applicable. There are many examples on the Internet, but later I thought it was too troublesome (every time it was the power of Ethernet troubles = .. =)
So we found the second method windowchrome.
Windowchrome is an open source library in Microsoft. Windows. Shell DLL.
Its principle is to overwrite a layer of controls on the outside of the form, which is similar to the two forms.
:
Note the following two points:
The first reason is that the button in the title bar cannot be hit due to overwriting, which may lead to incorrect selection or triggering. The following settings are required:
<Button shell: windowchrome. ishittestvisibleinchrome = " True " Style = " {Staticresource closebuttonstyle} " Horizontalalignment =" Right " Margin = " 0, 0, 25, 0 " Width = " 24 " Height = " 24 " Command = " {X: static shell: systemcommands. closewindowcommand} " Commandparameter = " {Binding elementname = selectdialog} " > </Button>
Windowchrome provides several commands by default, such as maximizing, minimizing, and disabling.
<Window. commandbindings> <commandbinding command ="{X: static shell: systemcommands. closewindowcommand}"Executed="_ Onsystemcommandclosewindow"/> </Window. commandbindings>Private Void_ Onsystemcommandclosewindow (ObjectSender, executedroutedeventargs e) {systemcommands. closewindow (window) E. Parameter );}
That's it.