mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-04 21:17:36 +08:00
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class ImagePreviewContainer
|
|
{
|
|
[Inject] private ImageService ImageService { get; set; }
|
|
|
|
private readonly IList<ImageRef> _previewList = new List<ImageRef>();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
ImageService.ImagePreviewOpened += HandlePreviewOpen;
|
|
ImageService.ImagePreviewClosed += HandlePreviewClose;
|
|
|
|
base.OnInitialized();
|
|
}
|
|
|
|
private void HandlePreviewOpen(ImageRef imageRef)
|
|
{
|
|
if (!_previewList.Contains(imageRef))
|
|
{
|
|
_previewList.Add(imageRef);
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void HandlePreviewClose(ImageRef imageRef)
|
|
{
|
|
if (_previewList.Contains(imageRef))
|
|
{
|
|
_previewList.Remove(imageRef);
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
ImageService.ImagePreviewOpened -= HandlePreviewOpen;
|
|
ImageService.ImagePreviewClosed -= HandlePreviewClose;
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|