Buttons zum Bilder switchen und Dialog.refresh

This commit is contained in:
klappstuhl24 2023-11-13 14:59:10 +01:00
parent 18e9d7ef5d
commit 5d8d3f1f2f
1 changed files with 33 additions and 10 deletions

View File

@ -33,40 +33,63 @@
</RadzenDataList> </RadzenDataList>
@code { @code {
IEnumerable<BildInfoModel>? _bildInfos; List<BildInfoModel>? _bildInfos;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
_bildInfos = await BildInfoData.GetAllBildInfosAsync(); _bildInfos = (await BildInfoData.GetAllBildInfosAsync()).ToList();
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }
async Task ShowImageDialog(BildInfoModel bildInfo) async Task ShowImageDialog(BildInfoModel bildInfo)
{ {
WunschInfoModel wunschInfo = await WunschInfoData.GetWunschInfoAsync(bildInfo.WunschId); WunschInfoModel wunschInfo = await WunschInfoData.GetWunschInfoAsync(bildInfo.WunschId);
int listIndex = _bildInfos.IndexOf(_bildInfos.First(info => info.Id == bildInfo.Id));
List<BildInfoModel> bilderVomWunsch = _bildInfos!.Where(info => info.WunschId == wunschInfo.Id).ToList(); List<BildInfoModel> bilderVomWunsch = _bildInfos!.Where(info => info.WunschId == wunschInfo.Id).ToList();
void ButtonLeft()
{
listIndex = (listIndex != 0) ? listIndex - 1 : 0;
bildInfo = _bildInfos[listIndex];
DialogService.Refresh();
}
void ButtonRight()
{
listIndex = (listIndex != _bildInfos.Count - 1) ? listIndex + 1 : _bildInfos.Count - 1;
bildInfo = _bildInfos[listIndex];
DialogService.Refresh();
}
var result = await DialogService.OpenAsync(wunschInfo.Wunsch, ds => var result = await DialogService.OpenAsync(wunschInfo.Wunsch, ds =>
@<div> @<div>
<RadzenStack Orientation="Orientation.Horizontal" Wrap="FlexWrap.Wrap"> <RadzenStack Orientation="Orientation.Horizontal" Wrap="FlexWrap.Wrap">
<RadzenStack Orientation="Orientation.Horizontal"> <RadzenStack Orientation="Orientation.Horizontal">
<RadzenStack Orientation="Orientation.Vertical"> <RadzenButton Click="ButtonLeft" Disabled="(listIndex == 0)" Style="border-radius: 0%"> </RadzenButton>
<RadzenImage Style="width: 400px; height: 400px;" Path="@bildInfo.Dateiname" /> <div>
</RadzenStack> <RadzenStack Orientation="Orientation.Vertical">
<RadzenText Text="@wunschInfo.BildBeschreibung"/> <RadzenImage Style="width: 400px; height: 400px;" Path="@bildInfo.Dateiname" />
</RadzenStack>
<RadzenText Text="@wunschInfo.BildBeschreibung" />
</div>
<RadzenButton Click="ButtonRight" Disabled="(listIndex == _bildInfos.Count - 1)" Style="border-radius: 0%"> </RadzenButton>
</RadzenStack> </RadzenStack>
@foreach (var bild in bilderVomWunsch) @foreach (var bild in bilderVomWunsch)
{ {
<RadzenImage class="small-image" Path="@bild.Dateiname" <RadzenImage class="small-image" Path="@bild.Dateiname"
Click="async () => { bildInfo = bild; DialogService.Close(); await ShowImageDialog(bild); }" /> Click="() => { bildInfo = bild; DialogService.Refresh(); }" />
} }
</RadzenStack> </RadzenStack>
</div>, </div>
,
new DialogOptions() { CloseDialogOnOverlayClick = true, Width = "50%" }); new DialogOptions() { CloseDialogOnOverlayClick = true, Width = "50%" });
} }
[Inject] [Inject]
private IWebHostEnvironment _environment { get; set; } private IWebHostEnvironment _environment { get; set; }
} }