The application class in WPF

Source: Internet
Author: User

You can set shutdownmode:onlastwindowclose in App.xaml (at which point you can change the Application.mainwindow property and reference other Windows) Onmainwindowclose Onexplicitshutdown (explicitly called Application.shutdown ()).

Calling the Application.shutdown () method causes the Application.Run () method to return immediately, but you can still run the other code in the main () method and handle the Application.exit event.

Common events for the application class, Startup Exit sessionending Activated Deactivated dispatcherunhandledexception, as follows:

<x:class= "Wpfapplication2.app"             xmlns= "http// Schemas.microsoft.com/winfx/2006/xaml/presentation "             xmlns:x="/http/ Schemas.microsoft.com/winfx/2006/xaml "             xmlns:local=" Clr-namespace:wpfapplication2 "               StartupUri= "MainWindow.xaml"  dispatcherunhandledexception= " Application_dispatcherunhandledexception ">

You can override the On+ event name in the application class to trigger an event, such as

    /// <summary>    /// the interactive logic    of App.xaml /// </summary>     Public Partial class app:application    {        protectedoverridevoid  onstartup (StartupEventArgs e)        {             Base . Onstartup (e);        }    }

Gets the instance of the current application application.current

Use the application class to achieve communication and management between different windows.

Implementation of a single-instance application.

Application classes in WPF

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.