/// <summary> /// The public configuration property that should be set with a configuration object, /// Will update view, when set. /// </summary> public void UpdateConfiguration(object configuration) { if (configuration == _configuration) { return; } _configuration = configuration; var optionGroup = new ConfigConverter().Convert(configuration); rootPanel.Controls.Clear(); int Y = 0; Control control; foreach (var option in optionGroup.ChildOptions) { if (option is OptionGroup) { var container = AddTopLevelOptionGroup((OptionGroup)option); if (option.Name == "DescriptionGroup") { container.Panel2Collapsed = false; } control = container; } else { control = CreateControl(option); rootPanel.Controls.Add(control); control.Location = new Point(topLevelGroupPaddingLeft, Y); } rootPanel.Controls.Add(control); Y += control.Height; } RecomputeSizes(null, null); initialized = true; }
private static void OnConfigurationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var self = (ConfigurationEditor)d; //reset ui view self.Content.Children.Clear(); if (e.NewValue == null) { return; } //convert the given object into an option var option = new ConfigConverter().Convert(e.NewValue); //get a ui element with the create method var uiElement = self.Create(option); //add the ui element to our view self.Content.Children.Add(uiElement); var itemsControl = uiElement as Panel; //if we have a panel, set its first expander to expanded if (itemsControl != null) { var expander = itemsControl.Children[0] as Expander; if (expander != null) { expander.IsExpanded = true; } } //Called to initialise the UI view, refreshes the isEnabled-states of relevant elements self.SomethingChanged(self, EventArgs.Empty); }