WPF (Application How to create an event, and its application related properties)

Source: Internet
Author: User

1. How to close the WPF program. The closure of the application is only possible if its shutdown method is called. There are three properties of shutdown. Onlastwindowclose,onmainwindowclose,onexplicitshutdown

1) by setting it directly in the App.xaml. Shutdown= "Onexplicitshutdown";

2) The second way: delete the App.xaml file, create a App.cs class yourself, in the Main method:

(Build Application object, build Win form object slightly)

App.shutdown=shutdownmodel. Onlastwindowclose;

App.run (Win);

2.Application also has many properties.

MainWindow Gets or sets the property

3. Add a Application event: Here are just two ways

On the App.xaml node, right-click on the property to find all of its properties and bind the event to the attribute you need. The result is as shown

This code will then appear in its App.xaml.cs file.

Then you need to change <page> to <applicationdefination> tag in this project file (*.csproj).

Two. The second approach is to implement the application event through the App.cs class

Win.show () displays the form.

App.run (Win) Startup form

App.exit+=application_exit; Delegate the application method to exit

void Application_exit (Objiect Sender,exiteventargs e) {}//The Exiteventargs here may differ depending on the event. Sender represents the object, and E represents some parameters for the event that is triggered.

WPF (Application How to create an event, and its application related properties)

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.