为什么Application.Current == NULL在一个WinForms应用程序? [英] Why does Application.Current == null in a WinForms application?

查看:865
本文介绍了为什么Application.Current == NULL在一个WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 Application.Current 出来空在一个WinForms应用程序? ?它是如何以及应该何时进行设置。



我做的:

 静态类节目{
///<总结>
///的主入口点应用程序。
///< /总结>
[STAThread]
静态无效的主要(){
Application.Run(新的MainForm());
}
}


解决方案

应用.Current是具体的WPF应用程序。
因此,当您使用WPF中的WinForms应用程序控件需要初始化WPF应用程序的实例。在你的WinForms应用程序做到这一点。

 如果(空== System.Windows.Application.Current)
$ { b $ b新System.Windows.Application();
}


Why does Application.Current come out to null in a WinForms application? How and when is it supposed to be set?

I am doing:

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

解决方案

Application.Current is Specific for WPF Application. Therefore when you are using WPF controls in WinForms Application you need to initialize instance of WPF Application. Do this in your WinForms Application.

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

这篇关于为什么Application.Current == NULL在一个WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆