英文:
Blazored Toast not showing up - Blazor Webassembly
问题
我尝试使用Blazored.Toast库(https://github.com/Blazored)实现Toast消息。我的问题是,如果我调用ShowInfo()方法(或类似的ShowError等方法),什么都不会发生。
我的代码如下:
我在Program.cs中注册了ToastService
WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddBlazoredToast();
//... 其他一些服务...
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>
按钮和样式看起来不错,但如果我按下按钮,什么都不会显示出来...
我是否漏掉了关键部分?
英文:
I try to implement Toastmessages from the Blazored.Toast Library (https://github.com/Blazored)
My problem is that nothing happens if I call the ShowInfo() Method (or similar one like ShowError, ...).
My code so far:
I registered the ToastService in Program.cs
WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddBlazoredToast();
//... Some other Services...
Configuration = builder.Configuration;
My Blazor component
@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>
The button incl. style is looking fine but if I press the button, nothing showing up...
Am I missing a key part?
答案1
得分: 2
所以我错过了从这些说明 (https://github.com/Blazored/Toast) 的第四步。
它说你必须将 BlazoredToasts 标签添加到 MainLayout.razor 中。
现在应该是这样的:
@inherits LayoutComponentBase
@* 这里是 BlazoredToast 标签... *@
<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>
在标签内部,你可以定义一些关于提示框的通用样式设置,例如位置或图标类型(更多信息请参考说明)。
英文:
So I've missed step 4 from the instructions (https://github.com/Blazored/Toast).
It says that you have to add the BlazoredToasts tag to the MainLayout.razor.
Now it should look like this:
@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>
Within the tag you can define some general stylesettings for the toasts like position or icontype. (More in the instructions)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论