using Avalonia.Controls; using Avalonia.Interactivity; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Desktop.ViewModels.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class LessonDialog : Window { public LessonDialog() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is LessonDialogViewModel vm) vm.OnPickAlternativePath = ShowAlternativePathDialog; } private async Task ShowAlternativePathDialog(Guid? currentId) { var dialogVm = new AlternativePathDialogViewModel( App.Services.GetRequiredService(), currentId); var dialog = new AlternativePathDialog { DataContext = dialogVm }; var ok = await dialog.ShowDialog(this); return ok ? dialogVm.Result : null; } private void OnSave(object? s, RoutedEventArgs e) { if (DataContext is LessonDialogViewModel vm && vm.SaveCommand.CanExecute(null)) { vm.SaveCommand.Execute(null); if (vm.Result is not null) Close(true); } } private void OnCancel(object? s, RoutedEventArgs e) => Close(false); }