using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Desktop.ViewModels.Workload; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Workload; public partial class WorkTaskListView : UserControl { public WorkTaskListView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is WorkTaskListViewModel vm) vm.OnEditTask = ShowEditDialog; } private async Task ShowEditDialog(WorkTask? source) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var groups = App.Services.GetRequiredService().GetAll(includeInactive: true); var vm = new AddEditWorkTaskDialogViewModel(source, groups); var dialog = new AddEditWorkTaskDialog { DataContext = vm }; await dialog.ShowDialog(owner); return vm.Result; } }