using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Desktop.ViewModels.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class GroupDetailView : UserControl { public GroupDetailView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is GroupDetailViewModel vm) vm.OnAddStudent = ShowAddStudentDialog; } private async Task ShowAddStudentDialog() { if (DataContext is not GroupDetailViewModel vm || vm.Group is null) return false; var dialogVm = new AddStudentToGroupDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), vm.Group.Id, vm.Group.SchoolYear); var dialog = new AddStudentToGroupDialog { DataContext = dialogVm }; var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return false; return await dialog.ShowDialog(owner); } }