public ConfigWindow(IWpfConfigurable module) { Owner = Application.Current.MainWindow; this.module = module; configuration = module.ConfigurationControl; InitializeComponent(); ConfigContent.Content = configuration; buttonSave.IsEnabled = configuration.CanSave; windowHeader.Text = configuration.Title; configuration.CanSavedChanged += configuration_CanSavedChanged; configuration.Loaded += Configuration_Loaded; // In constructor subscribe to the Change event of the WindowRect DependencyProperty DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(WindowRectProperty, typeof(ConfigWindow)); if (dpd != null) { dpd.AddValueChanged(this, delegate { ResizeWindow(WindowRect); }); } }
private void ChooseButtonClick(object sender, RoutedEventArgs e) { bool hasConfig = false; SelectedModule = (ModuleType)ModulesList.SelectedItem; SelectedModuleInstance = null; Type[] interfaceTypes = SelectedModule.Type.GetInterfaces(); foreach (Type interfaceType in interfaceTypes) { if (interfaceType.Equals(typeof(IWpfConfigurable))) { try { SelectedModuleInstance = (IWpfConfigurable)Activator.CreateInstance(SelectedModule.Type); configuration = SelectedModuleInstance.ConfigurationControl; ConfigContent.Content = configuration; buttonSave.IsEnabled = configuration.CanSave; windowHeaderConfig.Text = configuration.Title; configuration.Loaded += Configuration_Loaded; configuration.CanSavedChanged += Configuration_CanSavedChanged; configuration.SizeChanged += ConfigContent_SizeChanged; configuration.OnLoad(); } catch (Exception ex) { App.OutputException(ex); MessageBox.Show("Error creating " + SelectedModule.Name, "Mayhem: Error", MessageBoxButton.OK); } hasConfig = true; break; } } if (!hasConfig) { DialogResult = true; } }