我尝试从 Blazored.Toast 库实现 Toastmessages (https://github.com/Blazored) 我的问题是,如果我调用 ShowInfo() 方法(或类似的方法,如 ShowError,...),什么也不会发生。
到目前为止我的代码:
我在Program.cs中注册了ToastService
WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddBlazoredToast();
//... Some other Services...
Configuration = builder.Configuration;
我的 Blazor 组件
@inject IToastService toastService
@using Blazored.Toast.Configuration;
@using Blazored.Toast.Services;
<body>
<button class="btn btn-info" id="InfoButton" @onclick="@(() => toastService.ShowInfo("I'm an INFO message", settings => {settings.IconType = IconType.None; settings.Position = ToastPosition.BottomCenter;}))">Info Toast</button>
</body>
按钮包括。样式看起来不错,但如果我按下按钮,什么也没有显示......
我是否遗漏了关键部分?
所以我错过了说明中的第 4 步 (https://github.com/Blazored/Toast)。
它表示您必须将 BlazoredToasts 标签添加到 MainLayout.razor。
现在它应该看起来像这样:
@inherits LayoutComponentBase
@*And here we have the BlazoredToast Tag...*@
<BlazoredToasts />
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
在标签中,您可以为 toast 定义一些常规样式设置,例如位置或图标类型。 (更多说明)