public MainWindow(MainViewModel viewModel, NotifyIconService notifyIconService) { InitializeComponent(); this.viewModel = viewModel; this.DataContext = this.viewModel; notifyIconService.Clicked += (s, e) => this.ToggleWindow(); notifyIconService.CloseRequested += (s, e) => this.Close(); this.Loaded += (s, e) => { var windowHandle = new WindowInteropHelper(this).Handle; Win32Interop.HideWindowFromAltTab(windowHandle); Win32Interop.PowerSchemeChanged += this.OnPowerPlanChanged; Win32Interop.RegisterForPowerSettingNotification(windowHandle); this.viewModel.UpdatePowerPlans(); }; this.Closing += (s, e) => { var windowHandle = new WindowInteropHelper(this).Handle; Win32Interop.PowerSchemeChanged -= this.OnPowerPlanChanged; Win32Interop.UnregisterForPowerSettingNotification(windowHandle); }; }