在Blazor winforms应用程序中安装MudBlazor

whlutmcx  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(176)

我正在进行MudBlazor的安装,我对安装指南中的以下代码行有一些问题...

using MudBlazor.Services;

builder.Services.AddMudServices();

winforms默认情况下不包含构建器,所以我修改了program.cs文件,如下图所示...

internal static class Program
{
    public static IServiceProvider? ServiceProvider { get; set; }
    static void ConfigureServices()
    {
        var services = new ServiceCollection();
        services.AddMudServices();

        ServiceProvider = services.BuildServiceProvider();
    }
    /// <summary>
    ///  The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        // To customize application configuration such as set high DPI settings or default font,
        // see https://aka.ms/applicationconfiguration.
        ApplicationConfiguration.Initialize();
        ConfigureServices();
        Application.Run(new Form1());
        
    }
}
eni9jsuy

eni9jsuy1#

假设您已经正确设置了MudBlazor,按照Microsoft's website上的Blazor Winforms教程进行操作,看起来可以在窗体的构造函数中完成,如下所示:

using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor.Services;

namespace YourNamespace;
public Form1()
{
        InitializeComponent();

        var services = new ServiceCollection();
        services.AddWindowsFormsBlazorWebView();
        services.AddMudServices();
        blazorWebView1.HostPage = "wwwroot\\index.html";
        blazorWebView1.Services = services.BuildServiceProvider();
}

相关问题