Blazored Toast未显示 – Blazor Webassembly

huangapple go评论70阅读模式
英文:

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;


&lt;body&gt;
  &lt;button class=&quot;btn btn-info&quot; id=&quot;InfoButton&quot; @onclick=&quot;@(() =&gt; toastService.ShowInfo(&quot;I&#39;m an INFO message&quot;, settings =&gt; {settings.IconType = IconType.None; settings.Position = ToastPosition.BottomCenter;}))&quot;&gt;Info Toast&lt;/button&gt;
&lt;/body&gt;

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...*@
&lt;BlazoredToasts /&gt;
&lt;div class=&quot;page&quot;&gt;
    &lt;div class=&quot;sidebar&quot;&gt;
        &lt;NavMenu /&gt;
    &lt;/div&gt;

    &lt;main&gt;
        &lt;div class=&quot;top-row px-4&quot;&gt;
            &lt;a href=&quot;https://docs.microsoft.com/aspnet/&quot; target=&quot;_blank&quot;&gt;About&lt;/a&gt;
        &lt;/div&gt;

        &lt;article class=&quot;content px-4&quot;&gt;
            @Body
        &lt;/article&gt;
    &lt;/main&gt;
&lt;/div&gt;

Within the tag you can define some general stylesettings for the toasts like position or icontype. (More in the instructions)

huangapple
  • 本文由 发表于 2023年7月17日 19:57:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定