using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Services; using LehrerApp.Desktop.ViewModels.Planning; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Planning; public partial class TimetableView : UserControl { public TimetableView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is TimetableViewModel vm) vm.OnEditSlot = ShowSlotDialog; } private async Task ShowSlotDialog(TimetableCellItem cell) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null || cell.Weekday is null) return; var vm = new TimetableSlotDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), cell.Weekday.Value, cell.PeriodNumber, cell.Slot); var dialog = new TimetableSlotDialog { DataContext = vm }; await dialog.ShowDialog(owner); } }