1

I am new to GUI development, i was trying to develop a sample ui application using winforms and WPF.

I found some of the code missing in WPF

namespace WindowsFormsApplication3
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

        }
    }
}    
  1. Why this code is not present in WPF when the project is created
  2. Why we are using Application class, what is the need of this class?
4

2 回答 2

0

此代码不存在,因为在app.xaml定义中通常有一个StarupURI="window1.xaml"属性允许 WPF 基础结构连接场景背后的启动代码。当然你可以创建一个自定义的引导程序,你需要删除 StartupURI 属性并拦截应用程序启动来创建/显示一个窗口:

public partial class App
{
  protected override void OnStartup(StartupEventArgs e)
  {
    try
    {
      var mainView = new MainView();
      mainView.Show();
      mainView.DataContext = new YourDataContext();
    }
    catch (Exception ex)
    {
      Debug.WriteLine(ex);
    }
  }
}
于 2013-02-25T11:31:54.157 回答
0

WPF 使用Application.XamlandApplication.cs来启动您的应用程序。

它启动您的应用程序,您可以覆盖一些方法并选择如何启动您的应用程序,为您的应用程序应用常规配置和错误处理

于 2013-02-25T11:32:04.047 回答