- update channels and controllables when window is opened

master
Simon G 5 years ago
parent 029099ca23
commit 66398ad4a4
  1. 18
      Mystify/App.axaml.cs
  2. 6
      Mystify/ViewModels/MainWindowViewModel.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<MainModel>();
_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<object>
{
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();

@ -60,5 +60,11 @@ namespace Mystify.ViewModels
if (SelectedControllable != null)
SelectedChannel?.AllocateControllable(SelectedControllable);
});
public void UpdateChannelsAndControllables()
{
RaisePropertyChanged(() => Channels);
RaisePropertyChanged(() => Controllables);
}
}
}

Loading…
Cancel
Save