-
Notifications
You must be signed in to change notification settings - Fork 2
3. Getting started π
Artyom M edited this page Jun 29, 2022
·
4 revisions
To start using Microsoft.Extensions.Hosting.Wpf
you need to add following changes.
This will help Microsoft.Extensions.Hosting.Wpf
to find InitializeComponent
that WPF in generating.
public partial class App : Application, IApplicationInitializeComponent
{
}
We need to add new Main
entry point for our WPF application.
public class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
using IHost host = CreateHostBuilder(args)
.Build();
host.Run();
}
private static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureServices(ConfigureServices);
}
private static void ConfigureServices(HostBuilderContext hostContext, IServiceCollection services)
{
services.AddWpf<App>();
}
}
Now we need to change our csproj
in order to use that new entry point.
<StartupObject>[Namespace].Program</StartupObject>