C# WPF-应用程序启动时新建演示者

C# WPF-应用程序启动时新建演示者,c#,wpf,C#,Wpf,我是WPF的新手。在winforms中,我用来创建一个presenter并在static main()中新建它。演示者的构造函数将在显示窗体之前获得对主窗体的引用 MainPresenter presenter = new MainPresenter(myform); Application.Start(myform); 我怎样才能在WPF中做到这一点?我注意到App.xaml有一个“StartUri”属性,指定加载哪个表单。WPF应用程序的主要入口点在哪里?如何在这里更改默认行为 谢谢 您可

我是WPF的新手。在winforms中,我用来创建一个presenter并在static main()中新建它。演示者的构造函数将在显示窗体之前获得对主窗体的引用

MainPresenter presenter = new MainPresenter(myform);
Application.Start(myform);
我怎样才能在WPF中做到这一点?我注意到App.xaml有一个“StartUri”属性,指定加载哪个表单。WPF应用程序的主要入口点在哪里?如何在这里更改默认行为


谢谢

您可以在主窗体(在startUri中指定)的构造函数或加载事件中或在App.xaml.cs文件中执行此操作

这篇文章完美地演示了我需要的内容

这已添加到App.xaml应用程序声明中

然后我将事件连接到App.xaml.cs中

private void Application_Startup(object sender, StartupEventArgs e)
        {

        }
这也帮了大忙:

private void Application_Startup(object sender, StartupEventArgs e)
        {

        }