简体   繁体   English

为什么必须使用Application类才能使用WPF窗口?

[英]Why do I have to use the Application class to use WPF windows?

I create my Window class 我创建我的Window类

class myWin : Window
{
    public myWin()
    {
        Title = "My";
        MaxWidth = 500;
        MaxHeight = 500;
    } 
}

Why I can not run 'myWin' without run Application's instance? 为什么没有运行应用程序的实例就无法运行“ myWin”?

Runs, but with freeze (Do not work). 运行,但冻结 (不工作)。

myWin a = new myWin();
a.Show();

Works Perfectly! 完美的作品!

myWin a = new myWin();
a.Show();

Application b = new Application();
b.Run();

I am using Xamarin Studio 我正在使用Xamarin Studio

The reason is that the Application class implements all the necessary plumbing/infrastructure to run a Windows application. 原因是Application类实现了运行Windows应用程序所需的所有必要的管道/基础结构。

The main part is the management of the message pump which processes all the messages sent by the OS to the application, particularly the repaint events which trigger the ... repaint of the rendering surface of the application. 主要部分是消息泵的管理,该消息泵处理OS发送给应用程序的所有消息,尤其是重绘事件,这些事件触发应用程序渲染表面的重绘。

So what the Application.Run do is essentially starting the message pump . 因此, Application.Run所做的本质上是启动消息泵

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我必须在 WPF 中使用 DataGrid 在具有 Content 属性的对象之间使用类型转换? - Why do I have to use type casting between objects with Content properties using a DataGrid in WPF? 如何为WPF应用程序开发和使用CommonApplicationData特殊文件夹 - How do I develop and use the CommonApplicationData special folder for a WPF application 如何在 WPF 应用程序中使用 SharpDX.WIC.Bitmap? - How do I use a SharpDX.WIC.Bitmap in a WPF application? Silverlight可以在WPF Windows应用程序中使用吗? - Is silverlight can be use in wpf windows application? 为什么我必须使用 <T> on静态方法调用泛型类 - Why do I have to use <T> on static method call on a generic class C#:为什么我必须在类的变量中使用公共访问修饰符? - C#: Why do I have to use the public access modifier in class's vars? 为什么我必须在不是控制器的类中使用Response.Cookies.Add(…)的完整路径? - Why do I have to use the full path of Response.Cookies.Add(…) in a class that's not a controller? 为什么我必须使用UIElement.UpdateLayout? - Why do I have have to use UIElement.UpdateLayout? 为什么我在WPF中尝试使用行为时出错? - Why do I get an error trying to use Behaviors in WPF? 如果在应用程序中使用SQL Server,是否必须安装SQL Server? - Do I have to install SQL Server if i use it in my application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM