mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-02-04 05:35:44 +00:00
53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
@implements IDisposable
|
|
@using System.Collections.Specialized
|
|
|
|
<div aria-live="polite" class="rz-notification" style="@Style">
|
|
@if (Service?.Messages != null)
|
|
{
|
|
@for (var i = 0; i < Service.Messages.Count; i++)
|
|
{
|
|
<div @key="Service.Messages[i]">
|
|
@DrawMessage(i, Service.Messages[i])
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
@code {
|
|
[Inject] private NotificationService? Service { get; set; }
|
|
|
|
[Parameter]
|
|
public string? Style { get; set; }
|
|
|
|
RenderFragment DrawMessage(int index, NotificationMessage m)
|
|
{
|
|
return new RenderFragment(builder =>
|
|
{
|
|
var i = 0;
|
|
builder.OpenComponent(i, typeof(RadzenNotificationMessage));
|
|
builder.AddAttribute(i++, "Message", m);
|
|
builder.AddAttribute(i++, "Style", m.Style);
|
|
builder.CloseComponent();
|
|
});
|
|
}
|
|
|
|
void Update(object? sender, NotifyCollectionChangedEventArgs args)
|
|
{
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Service?.Messages != null)
|
|
{
|
|
Service.Messages.CollectionChanged -= Update;
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
if (Service?.Messages != null)
|
|
{
|
|
Service.Messages.CollectionChanged += Update;
|
|
}
|
|
}
|
|
} |