WPF learning notes-custom window

Source: Internet
Author: User

1. Add a new window in expression blend and set the attribute: allowstransparency = true, windowstyle = none, windowstartuplocation = centerscreen

Set the Alpha value of the window to 0 to make the original window transparent.

2. Delete the default grid element, add a border element from the toolbox, and set the attributes of border:

Cornerradius = "10, 10, 10" borderthickness = "8, 8, 8" background = "# ffffffff" borderbrush = "# cc000000"

3. Add a sub-border for border and set its attributes:

Cornerradius = "8, 8, 8" background = "#99 ffffff"

4. Add a grid element for the second border, and then add two rows for the grid:

Set the height of the first row to auto, and the height of the second row to * (1 star)

5. continue adding child elements:

Closewindowbutton is a custom button used to close a window.

6. My custom window is as follows:

However, this window cannot do anything. You cannot move the window position with the mouse or close the window directly. You also need to add some background information for her.Code

7. Add event processing code for windowtitlelabel and closewindowbutton:

Add code in:

Private void windowtitlelabel_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
{
This. dragmove ();
}

Private void closewindowbutton_click (Object sender, routedeventargs E)
{
This. Close ();
}

This is a success. Now, press and hold the title bar of the window to drag the window and click the close button to close the window.

Related Article

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.