/// <summary> /// Allows the user to edit the specic value in a dialog by displaying <see cref="TextEditDialog"/> to the user. /// </summary> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information. /// </param><param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services. /// </param><param name="value">The object to edit. /// </param> public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { var dialog = new TextEditDialog(); var bindableProperty = EditorUtility.GetBindableProperty(context); Debug.Assert(bindableProperty != null, "Could not locate bindable property from ITypeDescriptorContext"); bool isTextReadOnly = EditorUtility.IsTextReadOnly(bindableProperty); var valueToEdit = new PopupEditorValue() { Value = value as string }; dialog.DataContext = valueToEdit; var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf)); var result = service.ShowDialog(dialog); if (result.HasValue && result.Value) { // We can't rely on the VS property grid to properly // if the property is attributed with EditorWithReadOnlyText(true) // so we set the bindable value ourselves. if (isTextReadOnly) { bindableProperty.Value = valueToEdit.Value; } return(valueToEdit.Value); } return(value); }
/// <summary> /// Allows the user to edit the specic value in a dialog by displaying <see cref="TextEditDialog"/> to the user. /// </summary> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information. /// </param><param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services. /// </param><param name="value">The object to edit. /// </param> public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) { var dialog = new TextEditDialog(); var bindableProperty = EditorUtility.GetBindableProperty(context); Debug.Assert(bindableProperty != null, "Could not locate bindable property from ITypeDescriptorContext"); bool isTextReadOnly = EditorUtility.IsTextReadOnly(bindableProperty); var valueToEdit = new PopupEditorValue() {Value = value as string}; dialog.DataContext = valueToEdit; var service = (IUIServiceWpf) provider.GetService(typeof(IUIServiceWpf)); var result = service.ShowDialog(dialog); if (result.HasValue && result.Value) { // We can't rely on the VS property grid to properly // if the property is attributed with EditorWithReadOnlyText(true) // so we set the bindable value ourselves. if (isTextReadOnly) bindableProperty.Value = valueToEdit.Value; return valueToEdit.Value; } return value; }