简体   繁体   中英

Customizing App.xaml.cs

I am trying to do some customization to App.xaml.cs to try to set some behaviors/events. Mostly researching, nothing special.

But whatever I do to the App.xaml.class there is no effect. I even emptied the App.xaml.cs class (nothing in it) and the WPF program still compiles.

I cant even start learning until I solve this mystery.

There's no mystery. It's possible to completely empty App.xaml.cs , because it is a partial class. The App.xaml is perfectly capable of standing on its own.

To do customization, take a look at the Application class on MSDN, in particular the section under "Remarks", which has info about the application life cycle, and application-scope objects (window, resources).

If you want to do customization, you can implement a StartUp event, and do your customization there.

You define the event in App.xaml:

<Application x:Class="Test.App"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                Startup="Application_Startup">

And if you remove the StartUpUri, you can also instantiate the main window for yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM