// Helper that tries to find the first applicable DialogPropertyValueEditor private DialogPropertyValueEditor FindDialogPropertyValueEditor() { PropertyEntry property = this.PropertyEntry; DialogPropertyValueEditor editor = null; // Look at property if (property != null) { editor = property.PropertyValueEditor as DialogPropertyValueEditor; } if (editor != null) { return(editor); } // Does the property have standard values? if (property != null && property.HasStandardValuesInternal) { editor = this.DefaultStandardValuesPropertyValueEditor as DialogPropertyValueEditor; } if (editor != null) { return(editor); } // Use the default editor = this.DefaultPropertyValueEditor as DialogPropertyValueEditor; return(editor); }
private static void OnActiveEditModePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { PropertyContainer theThis = (PropertyContainer)obj; // Ensure that the Template property of this control is set to the right ControlTemplate UpdateControlTemplate(theThis); // Invoke a dialog editor if needed if (object.Equals(e.NewValue, PropertyContainerEditMode.Dialog)) { if (OpenDialogWindow.CanExecute(null, theThis)) { // There is someone who handles this command, so let it deal with it // however it wants. OpenDialogWindow.Execute(null, theThis); } else { // There is no-one handling this command, so see if there is a virtual // method we can invoke DialogPropertyValueEditor editor = theThis.FindDialogPropertyValueEditor(); if (editor != null) { // If the DialogCommandSource is not explicitly set, use this control as the // command source IInputElement dialogCommandSource = theThis.DialogCommandSource ?? theThis; editor.ShowDialog(theThis.PropertyEntry.PropertyValue, dialogCommandSource); } } // And revert back to old edit mode once done theThis.ActiveEditMode = (PropertyContainerEditMode)e.OldValue; } }