[英]Is it necessary to inherit System.Windows.Application base class for WPF Application?
In VS2015, when we generated new WPF project, it contains App.xaml(.cs).在 VS2015 中,当我们生成新的 WPF 项目时,它包含 App.xaml(.cs)。 I suppose that it will be an entry point of WPF application.我想这将是 WPF 应用程序的入口点。 Then App.xaml.cs
becomes like:然后App.xaml.cs
变成这样:
...
using System.Windows;
namespace WpfApplication
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
Now, I remove inheritance of System.Windows.Application
, still it seems to be working...现在,我删除了System.Windows.Application
继承,但它似乎仍然有效......
- public partial class App : Application
+ public partial class App
So let me ask: App
class does not need to inherit System.Windows.Application
?那么请问: App
类不需要继承System.Windows.Application
吗? What is the difference?有什么不同?
thanks.谢谢。
No it is not required.不,这不是必需的。 In your code you have the class defined as partial
, this allows your code and autogenerated code by the compiler to be combined.在您的代码中,您将类定义为partial
,这允许您的代码和编译器自动生成的代码组合在一起。
In your App.xaml you have在你的 App.xaml 你有
<Application x:Class="WpfApplication.App" ...
This tells the compiler you are creating a object of type Application
with the name WpfApplication.App
so the auto-generated code will include the inherited type class.这告诉编译器您正在创建一个名为WpfApplication.App
Application
类型的对象,因此自动生成的代码将包含继承的类型类。 Once your WpfApplication.App
code is combined with the auto-generated WpfApplication.App
the inheritance is already defined.一旦您的WpfApplication.App
代码与自动生成的WpfApplication.App
结合,继承就已经定义了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.