2000 basic WPF small poses you should know <74-77 WPF multi-window tips>

Source: Internet
Author: User

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]

  

#74 overriding the source standard event (OnXXX) in the application class

In the application class, we can write about the processing method (handler) of startup, Exit, sessionending and other source events.

There is also a way to add a logic-override onxxx method when these events are triggered (OnXxx refers to the handling of the corresponding event). These methods are the source methods that the application class executes when an event is triggered. This way you can just rewrite the method in App.xaml.cs.

The following example overrides the Onsessionending method when sessionending is in the moment:

 Public Partial class app:application{        protectedoverridevoid  onsessionending ( SessionEndingCancelEventArgs e)        {            // Always call method in base class, so the the event get S raised.            Base . Onsessionending (e);              // Place your own sessionending logic here         }}

#75 creating and presenting a second window

You can create a second window in addition to MainWindow while the WPF program is running.

Step: Add a window to the project as the second Windows.

  

  

You can directly instantiate the second window in your code and call the Show method:

  

Private void Button_Click (object  sender, System.Windows.RoutedEventArgs e) {    new  Anotherwindow ();    Win. Show ();}

 #76 Application Windows Property lists all the current window

Application has a property called Windows that can get all the windows in the current application.

For example, there are two buttons, one is to create a new window, and the other is to display all of the window information.

  

Createnewwindow button:

  

Private void Btncreate_click (object  sender, System.Windows.RoutedEventArgs e) {    new Anotherwindow ();     = DateTime.Now.ToLongTimeString ();    Win. Show ();}

Where is the Windows?, listing all window:

  

Private void Btnwhere_click (object  sender, RoutedEventArgs e) {    new  StringBuilder ();     foreach inch App.Current.Windows)    {        sb. AppendFormat ("window [{0}] is at ({1},{2}). \ n", W.title, W.top, w.left); c17/>}     "My Windows");}

Final Result:

  

  

#77 A parent-child relationship between windows

Create a new window and invoke the Show method to show that the window is separate from other windows. It can be maximized to minimize the rest of the form and will also have its own window icon in the taskbar.

  

New= DateTime.Now.ToLongTimeString (); W.show ();

WPF supports parent-child relationships between windows. You can set the Owner property to set the parent-child relationship between windows

  

Newstring. Format ("Child#{0}"this1this; W.show ();

The parent-child relationship between windows can be summed up as:

1. When the parent window is minimized, all of the child windows are minimized.

2. When the child window is minimized, the parent window is not minimized.

3. The child windows can interact with each other, they are lateral.

4. The parent window does not overwrite the child window, that is, the child window is always above the parent window.

5. Closing the parent window causes all child windows to close.

There will be more about WPF dialog and location in the next issue, I hope to pay more attention ~

2000 articles you should know about WPF small Posture Basics <74-77 WPF multi-window tips>

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.