我正在使用.net8和Blazor和流畅的UI库,我得到一个错误,即使我在MainLayout的末尾将其添加到App.razor App.razor中,也没有找到任何提供者.
Program.cs
builder.Services.AddHttpClient();
builder.Services.AddFluentUIComponents();
App.razor App.razor
<script src="_content/Microsoft.FluentUI.AspNetCore.Components/js/loading-theme.js" type="text/javascript"></script>
<script src="_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js" type="module" async></script>
MainLayout.razor
<FluentLayout>
<FluentHeader>
<Header/>
</FluentHeader>
<FluentStack Orientation="Orientation.Horizontal" Width="100%" Class="page--container">
<NavMenu/>
<FluentBodyContent>
@Body
</FluentBodyContent>
</FluentStack>
</FluentLayout>
<FluentDialogProvider/>
<FluentToastProvider/>
<FluentTooltipProvider/>
Header.razor
[Inject] public IDialogService DialogService { get; set; }
private async Task ToggleThemeHandler()
{
var dialog = DialogService.ShowDialogAsync<MenuPanel>(new DialogParameters
{
Alignment = HorizontalAlignment.Right
});
await dialog;
}
MenuPanel.razor
@implements IDialogContentComponent
<FluentDialogBody>
Menu
</FluentDialogBody>
IDE控制台
Unhandled exception rendering component: <FluentDialogProvider /> needs to be added to the main layout of your application/site. (Parameter
'OnShowAsync')
System.ArgumentNullException: <FluentDialogProvider /> needs to be added to the main layout of your application/site. (Parameter 'OnShowAsyn
c') at Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowDialogAsync[TData](Type dialogComponent, TData data, DialogParameters param
eters) in /_/src/Core/Components/Dialog/Services/DialogService-Dialog.cs:line 17 at Microsoft.FluentUI.AspNetCore.Components.DialogService.ShowDialogAsync[TDialog](DialogParameters parameters) in /_/src/Core/Components/Dialog/Services/DialogService-Dialog.cs:line 35 at Components.Layouts.MainLayout.Components.Header.ToggleThemeHandler() in **\Components\Layouts\MainLayout\Components\Header.razor:line 36