c# - 为什么 Application.Current == null 在 WinForms 应用程序中?

标签 c# winforms

为什么 Application.Current 在 WinForms 应用程序中出现为空?应该如何以及何时设置?

我在做:

 static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.Run(new MainForm());
        }
    }

最佳答案

Application.Current 特定于 WPF 应用程序。 因此,当您在 WinForms 应用程序中使用 WPF 控件时,您需要初始化 WPF 应用程序的实例。在您的 WinForms 应用程序中执行此操作。

if ( null == System.Windows.Application.Current )
{
   new System.Windows.Application();
} 

关于c# - 为什么 Application.Current == null 在 WinForms 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35902815/

相关文章:

c# - ASP.NET 无法解析 xml!检查文件路径

c# - 为什么 Extender Provider Properties 在 C# 窗口应用程序中的 Designer 中丢失?

c# - 将字符串集合绑定(bind)到 ListView、Windows 窗体

c# - 在 Datagridview 中分组

c# - 如何在 WinForms 中对 URL 进行编码?

c# - 多线程代码卡在 Form.ShowDialog() 语句中

c# - 泛型中如何判断T是值类型还是引用类?

c# - 如何在 C# SDK 中为具有工作负载身份的 GCS 生成签名 URL?

将枚举值的通用列表组合为单个值的 C# 方法

c# - 通过 Windows 应用程序检查远程文件夹中的文件