ant-design-blazor/components/drawer/DrawerContainer.razor.cs
zxyao db64810a20 feat: add DrawerService (#241)
* refactor: change confirm return

* feat(module: drawer): add DrawerService

* fix: change type EventCallback in configs to Func

* fix: typo

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-06-23 15:19:44 +08:00

50 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
namespace AntDesign
{
public partial class DrawerContainer
{
[Inject]
private DrawerService DrawerService { get; set; }
protected override void OnInitialized()
{
DrawerService.OnCreate += DrawerService_OnCreate;
DrawerService.OnClose += DrawerService_OnClose;
}
protected override void Dispose(bool disposing)
{
DrawerService.OnCreate -= DrawerService_OnCreate;
DrawerService.OnClose -= DrawerService_OnClose;
base.Dispose(disposing);
}
private List<DrawerConfig> _drawerConfigs = new List<DrawerConfig>();
private async Task DrawerService_OnClose(DrawerConfig arg)
{
arg.Visible = false;
await InvokeAsync(StateHasChanged);
}
private async Task DrawerService_OnCreate(DrawerConfig arg)
{
arg.Visible = true;
if (!_drawerConfigs.Contains(arg))
{
_drawerConfigs.Add(arg);
}
await InvokeAsync(StateHasChanged);
}
}
}