1. 将App.xaml中的StartupUri删去
  2. 调整App.xaml.cs,重写OnStartup方法
public partial class App : Application
    {
        ServiceProvider serviceProvider { get; set; }

        protected override void OnStartup(StartupEventArgs e)
        {
            var service=new ServiceCollection();

            ConfigurationService(service);

            serviceProvider = service.BuildServiceProvider();

            var mainView = serviceProvider.GetRequiredService<MainWindow>();
            mainView.Show();

            base.OnStartup(e);
        }

        private void ConfigurationService(ServiceCollection service)
        {
            //注入
            service.AddTransient(typeof(MainWindow));
        }
    }

相关文章:

  • 2022-02-18
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2021-11-19
  • 2021-07-28
  • 2022-01-15
  • 2021-10-11
  • 2022-12-23
相关资源
相似解决方案