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 TimeTrackingView : UserControl { public TimeTrackingView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is TimeTrackingViewModel vm) vm.OnAddEntry = ShowAddEntryDialog; } private async Task ShowAddEntryDialog() { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var tasks = App.Services.GetRequiredService() .GetAll().Where(t => t.Status != WorkTaskStatus.Done).ToList(); var vm = new AddTimeEntryDialogViewModel(tasks); var dialog = new AddTimeEntryDialog { DataContext = vm }; await dialog.ShowDialog(owner); return vm.Result; } }