private void OnLaunchOnStartupCheckUncheck(bool value) { if (isApplicationInStartup != value) { isApplicationInStartup = value; if (isApplicationInStartup) { WindowsStartupHelper.AddApplicationToStartup(); } else { WindowsStartupHelper.RemoveApplicationFromStartup(); } } }
public MainWindow() { InitializeComponent(); isApplicationInStartup = WindowsStartupHelper.IsApplicationInStartup(); bool.TryParse(ConfigurationHelper.ReadVariable(Config.SHOW_ALL_INDICATORS), out showAllIndicators); // Taskbar menu MenuItem showIndicators = new MenuItem { Header = "Show Indicators", IsCheckable = true, IsChecked = showAllIndicators }; showIndicators.Checked += (sender, args) => OnShowIndicatorsCheckUncheck(true); showIndicators.Unchecked += (sender, args) => OnShowIndicatorsCheckUncheck(false); MenuItem launchOnStartup = new MenuItem { Header = "Launch on Windows startup", IsCheckable = true, IsChecked = isApplicationInStartup }; launchOnStartup.Checked += (sender, args) => OnLaunchOnStartupCheckUncheck(true); launchOnStartup.Unchecked += (sender, args) => OnLaunchOnStartupCheckUncheck(false); MenuItem quit = new MenuItem { Header = "Quit" }; quit.Click += (sender, args) => App.Current.Shutdown(); taskIcon = new TaskbarIcon { ToolTipText = "Key Indicator" }; taskIcon.ContextMenu = new ContextMenu(); taskIcon.ContextMenu.Items.Add(showIndicators); taskIcon.ContextMenu.Items.Add(launchOnStartup); taskIcon.ContextMenu.Items.Add(new Separator()); taskIcon.ContextMenu.Items.Add(quit); UpdateIndicators(); fadeInOutWorker.ProgressChanged += (sender, args) => { switch (args.ProgressPercentage) { case 0: Show(); break; case 1: Hide(); break; } }; fadeInOutWorker.DoWork += (sender, args) => { fadeInOutWorker.ReportProgress(0); while (ticks < 10) { ticks++; System.Threading.Thread.Sleep(50); } fadeInOutWorker.ReportProgress(1); }; }