private void Window_Closed(object sender, EventArgs e) { foreach (var m in Models) { switch (m) { case INotifyPropertyChanged config when SaveMethod != null: SaveMethod(config); break; case INotifyPropertyChangedEx config: if (config.IsChanged) { config.IsChanged = false; Svc.Configuration.Save(m, m.GetType()).RunAsync(); } break; case INotifyPropertyChanged _: Svc.Configuration.Save(m, m.GetType()).RunAsync(); break; } } Dispatcher.Invoke(() => SingletonSemaphore.Release()); }
/// <summary>Instantiates a new <see cref="ConfigurationWindow" /> if none other exist</summary> /// <param name="hotKeyManager"> /// An optional instance of a <see cref="HotKeyManager" /> that will /// be used to provide hotkey rebinding options to the user /// </param> /// <param name="configModels">The configuration class instances that should be displayed</param> /// <returns>New instance or <see langword="null" /></returns> public static ConfigurationWindow ShowAndActivate(HotKeyManager hotKeyManager, params INotifyPropertyChanged[] configModels) { return(Application.Current.Dispatcher.Invoke(() => { if (SingletonSemaphore.WaitOne(0) == false) { return null; } var cfgWdw = new ConfigurationWindow(hotKeyManager, configModels); cfgWdw.ShowAndActivate(); return cfgWdw; })); }