[英]Customizing App.xaml.cs
I am trying to do some customization to App.xaml.cs
to try to set some behaviors/events. 我正在尝试对
App.xaml.cs
进行一些自定义以尝试设置一些行为/事件。 Mostly researching, nothing special. 主要是研究,没什么特别的。
But whatever I do to the App.xaml.class
there is no effect. 但无论我对
App.xaml.class
做什么都没有效果。 I even emptied the App.xaml.cs
class (nothing in it) and the WPF program still compiles. 我甚至清空了
App.xaml.cs
类(其中没有任何东西),WPF程序仍在编译。
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. 可以完全清空
App.xaml.cs
,因为它是一个部分类。 The App.xaml
is perfectly capable of standing on its own. App.xaml
完全有能力站立起来。
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). 要进行自定义,请查看MSDN上的
Application
类,特别是“备注”下的部分,其中包含有关应用程序生命周期和应用程序范围对象(窗口,资源)的信息。
If you want to do customization, you can implement a StartUp event, and do your customization there. 如果要进行自定义,可以实现StartUp事件,并在那里进行自定义。
You define the event in App.xaml: 您在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. 如果删除StartUpUri,您也可以自己实例化主窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.