2020-10-25 19:52:14 +00:00
|
|
|
|
using RGBController2.ViewModels;
|
2020-11-03 14:24:46 +00:00
|
|
|
|
using System;
|
2020-10-25 19:52:14 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace RGBController2.Views
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
2020-11-03 14:24:46 +00:00
|
|
|
|
private System.Windows.Forms.NotifyIcon _notifyIcon;
|
2020-10-25 19:52:14 +00:00
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
// This allows the biniding to be done to the MainViewModel.cs class rather than this one.
|
|
|
|
|
// Why? Something to do with MVVM & good practice?
|
2020-10-27 20:07:26 +00:00
|
|
|
|
var viewModel = new MainViewModel();
|
|
|
|
|
DataContext = viewModel;
|
2020-10-29 20:47:52 +00:00
|
|
|
|
|
|
|
|
|
// We are using this to hook on the closing event so that we can save our config when the application is closed
|
2020-10-27 20:07:26 +00:00
|
|
|
|
Closing += viewModel.OnWindowClosing;
|
2020-11-03 14:24:46 +00:00
|
|
|
|
|
|
|
|
|
// System tray code
|
|
|
|
|
// This should all probally be in the view model, but then I cannot
|
|
|
|
|
// access the window state and this object
|
|
|
|
|
_notifyIcon = new System.Windows.Forms.NotifyIcon();
|
|
|
|
|
_notifyIcon.Icon = new System.Drawing.Icon("logo.ico");
|
|
|
|
|
_notifyIcon.MouseDoubleClick +=
|
|
|
|
|
new System.Windows.Forms.MouseEventHandler
|
|
|
|
|
(NotifyIcon_MouseDoubleClick);
|
|
|
|
|
this.StateChanged += this.Window_StateChanged;
|
|
|
|
|
|
|
|
|
|
// Start minimised
|
|
|
|
|
WindowState = WindowState.Minimized;
|
|
|
|
|
this.ShowInTaskbar = false;
|
|
|
|
|
_notifyIcon.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_StateChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.WindowState == WindowState.Minimized)
|
|
|
|
|
{
|
|
|
|
|
this.ShowInTaskbar = false;
|
|
|
|
|
_notifyIcon.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else if (this.WindowState == WindowState.Normal)
|
|
|
|
|
{
|
|
|
|
|
_notifyIcon.Visible = false;
|
|
|
|
|
this.ShowInTaskbar = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotifyIcon_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.WindowState = WindowState.Normal;
|
2020-10-25 19:52:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|