Another Implementation Method of WPF Custom forms

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.