init 1.0.0
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using LehrerApp.Desktop.ViewModels;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
using LehrerApp.Desktop.Views;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace LehrerApp.Desktop;
|
||||
|
||||
public class App : Application
|
||||
{
|
||||
public static IServiceProvider Services { get; private set; } = null!;
|
||||
|
||||
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
Services = AppBootstrapper.BuildServices();
|
||||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var mainVm = Services.GetRequiredService<MainWindowViewModel>();
|
||||
WireCallbacks(mainVm);
|
||||
desktop.MainWindow = new MainWindow { DataContext = mainVm };
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private static void WireCallbacks(MainWindowViewModel main)
|
||||
{
|
||||
// GroupList → GroupDetail
|
||||
var gl = Services.GetRequiredService<GroupListViewModel>();
|
||||
gl.OnNavigateToDetail = id => main.NavigateToGroupDetail(id);
|
||||
gl.OnAddGroup = () => ShowAddGroupDialog(gl);
|
||||
|
||||
// Dashboard → GroupDetail (Chips)
|
||||
var dash = Services.GetRequiredService<DashboardViewModel>();
|
||||
dash.OnNavigateToGroup = id => main.NavigateToGroupDetail(id);
|
||||
|
||||
// StudentList → StudentDetail
|
||||
var sl = Services.GetRequiredService<StudentListViewModel>();
|
||||
sl.OnNavigateToDetail = id => main.NavigateToStudent(id);
|
||||
}
|
||||
|
||||
private static async void ShowAddGroupDialog(GroupListViewModel groupList)
|
||||
{
|
||||
var vm = new ViewModels.Groups.AddGroupDialogViewModel(
|
||||
Services.GetRequiredService<Core.Interfaces.IGroupRepository>(),
|
||||
Services.GetRequiredService<Core.Services.SchoolYearService>());
|
||||
var dialog = new Views.Groups.AddGroupDialog { DataContext = vm };
|
||||
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var ok = await dialog.ShowDialog<bool>(owner);
|
||||
if (ok) groupList.LoadGroups();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user