From 66398ad4a4b15ebd2f7f7d1b0c8af5ce7a79da87 Mon Sep 17 00:00:00 2001 From: Simon G Date: Wed, 14 Apr 2021 10:06:56 +0200 Subject: [PATCH] - update channels and controllables when window is opened --- Mystify/App.axaml.cs | 18 ++++++++++++------ Mystify/ViewModels/MainWindowViewModel.cs | 6 ++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Mystify/App.axaml.cs b/Mystify/App.axaml.cs index 04e28b1..8a2ffff 100644 --- a/Mystify/App.axaml.cs +++ b/Mystify/App.axaml.cs @@ -20,6 +20,7 @@ namespace Mystify private IIocContainer? _kernel; private INotifyIcon? _notifyIcon; private MainWindow? _mainWindow; + private MainWindowViewModel? _mainWindowViewModel; public override void Initialize() => AvaloniaXamlLoader.Load(this); public override void OnFrameworkInitializationCompleted() @@ -31,10 +32,9 @@ namespace Mystify _kernel = bootstrapper.BootstrapKernel(); MainModel mainModel = _kernel.Resolve(); - _mainWindow = new MainWindow(); - - MainWindowViewModel mainWindowViewModel = new (mainModel, _mainWindow); - _mainWindow.DataContext = mainWindowViewModel; + _mainWindow = new(); + _mainWindowViewModel = new (mainModel, _mainWindow); + _mainWindow.DataContext = _mainWindowViewModel; if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) { @@ -48,20 +48,26 @@ namespace Mystify { Items = new List { - new MenuItem {Header = "Open Mystify", Command = ReactiveCommand.Create(() => _mainWindow?.Show())}, + new MenuItem {Header = "Open Mystify", Command = ReactiveCommand.Create(OpenMainWindow)}, new Separator(), new MenuItem {Header = "Close", Command = ReactiveCommand.Create(() => desktopStyleApplicationLifetime.Shutdown())} } }; _notifyIcon.ContextMenu = notifyIconContextMenu; - _notifyIcon.DoubleClick += (_, _) => _mainWindow?.Show(); + _notifyIcon.DoubleClick += (_, _) => OpenMainWindow(); _notifyIcon.Visible = true; } base.OnFrameworkInitializationCompleted(); } + private void OpenMainWindow() + { + _mainWindowViewModel?.UpdateChannelsAndControllables(); + _mainWindow?.Show(); + } + private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs args) { _mainWindow?.Close(); diff --git a/Mystify/ViewModels/MainWindowViewModel.cs b/Mystify/ViewModels/MainWindowViewModel.cs index 2f03853..df8cf8c 100644 --- a/Mystify/ViewModels/MainWindowViewModel.cs +++ b/Mystify/ViewModels/MainWindowViewModel.cs @@ -60,5 +60,11 @@ namespace Mystify.ViewModels if (SelectedControllable != null) SelectedChannel?.AllocateControllable(SelectedControllable); }); + + public void UpdateChannelsAndControllables() + { + RaisePropertyChanged(() => Channels); + RaisePropertyChanged(() => Controllables); + } } }