2000 What you should know about WPF small Posture Basics <78-81 DIALOG/LOCATION/WPF Device Independence >

Source: Internet
Author: User

Original: 2000 articles you should know about WPF small Posture Basics <78-81 DIALOG/LOCATION/WPF Device Independence >

A person needs to be introduced before the text begins: Sean Sexton. A software engineer from Minnesota Twins. Best of all, he maintained two blogs:2,000things you should Know about C # and 2,000 things you should Know about W PF . He updates one of the most important and easily forgotten knowledge of WPF and C # every day with a short 150-word language like Weibo. I hope I can share it with you.

This series I will not only translate his every tip, but also join his own development of ideas and insights. This series I want to be able to stick with him as well, every day of progress to promote greatness.

Here is a solemn explanation. The series is based on Mr. Sean Sexton's English blog, and Sean Sexton has full copyright and revocation rights.

  You can read the article on the WPF tab of this blog earlier. View past period

  [ Small Nine school, dedicated to the ordinary language to describe the extraordinary technology.] If you want to reprint, please indicate the source: Small nine of the academy . cnblogs.com/xfuture]

  

#78 Modal Dialog and Modeless Window

  Modal Dialog (modal window) is a window that appears before other windows of the program, blocking interaction with other windows until it closes. Minimizing modal window also minimizes all remaining windows.

  Modeless window is a normal form that does not hinder interaction with the rest of the window and does not interfere with each other.

Choose different window types depending on the business situation in the actual application.

The following example uses window. Show and window. ShowDialog methods to show non-modal windows and modal windows separately.

Private voidBtnmodal_click (Objectsender, RoutedEventArgs e) {ChildWindow win=NewChildWindow (); Win. Title="Modal Child-"+DateTime.Now.ToLongTimeString (); Win. ShowDialog ();} Private voidBtnmodeless_click (Objectsender, RoutedEventArgs e) {ChildWindow win=NewChildWindow (); Win. Title="Modeless Window-"+DateTime.Now.ToLongTimeString (); Win. Show ();}    

  

Example of #79 Modal Dialog and Modeless window (using Windows comes with Notepad)

Notepad running Windows comes with the modal dialog and modeless dialog two forms.

After opening Notepad, enter some text and click Find edit| Find (ctrl+f). You can see that you can switch between the main form and the Search window at will. So find dialog is a modeless dialog, and you can still interact with the main form.

  

Then close the Find window and click file| Print (CTRL+P) opens the printed form. When the print form is present, you can see that you are not able to switch to the main form. The print form is a modal window (Modal Dialog).

  

  

#80 Window Size and location

The window class has left and top properties to locate its position in the display. You also have width and height to specify the window size. The values are assigned to device-independent units (devices independent units).

Assuming that your screen has a DPI setting of 96Dpi (dots per inch), the units that WPF uses are device-independent units. When you set it to 96 units, it is 1 inch high. If it is a different dpi, follow the conversion formula:

# pixels = (# WPF Units) * (DPI/96)

This way the WPF program is displayed in the same size display, regardless of the pixel density.

 #81 WPF Units

In Windows Form, the control size is controlled by pixel. In WPF, device-independent, which is controlled by WPF units.

1 WPF unit = 1/96 inch. That is, on a 96DPI display, 1 WPF Unit = 1 pixel.

That is, in a 120DPI environment, 1 WPF unit = 1.25 pixels. (120/96).

Similar device independence can be achieved in Windows Form by modifying the AutoScaleMode property of the form, which is automatic in WPF.

Formula: # pixels = (# WPF Units) * (DPI/96)

  

  

The next issue will be more about WPF GUI and application cycle, I hope to pay more attention to ~

2000 What you should know about WPF small Posture Basics <78-81 DIALOG/LOCATION/WPF Device Independence >

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.