Browse Source

Fixed NullableBoolEditor: the editor must be able to show the difference between the null value and an ambiguous value (multiple selected components with different values).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2672 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
a9aca4d7b1
  1. 49
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/NullableBoolEditor.cs

49
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/NullableBoolEditor.cs

@ -14,37 +14,42 @@ namespace ICSharpCode.WpfDesign.Designer.Controls.TypeEditors
[TypeEditor(typeof(bool?))] [TypeEditor(typeof(bool?))]
public class NullableBoolEditor : ComboBox public class NullableBoolEditor : ComboBox
{ {
readonly static Entry[] entries = { const string NullString = "Null";
new Entry(SharedInstances.BoxedTrue, bool.TrueString),
new Entry(SharedInstances.BoxedFalse, bool.FalseString),
new Entry(null, "Null")
};
public NullableBoolEditor(IPropertyEditorDataProperty property) public NullableBoolEditor(IPropertyEditorDataProperty property)
{ {
this.SelectedValuePath = "Value"; // the UI must show the difference between an ambiguous property value
this.ItemsSource = entries; // and null, so we use a combo box bound to a string property
SetBinding(ComboBox.SelectedValueProperty, PropertyEditorBindingHelper.CreateBinding(this, property)); property = new NullableBoolToStringProperty(property);
this.ItemsSource = new string[] { NullString, false.ToString(), true.ToString() };
SetBinding(ComboBox.SelectedItemProperty, PropertyEditorBindingHelper.CreateBinding(this, property));
} }
sealed class Entry /// <summary>
/// views a bool? property as string property
/// </summary>
sealed class NullableBoolToStringProperty : ProxyPropertyEditorDataProperty
{ {
object val; public NullableBoolToStringProperty(IPropertyEditorDataProperty data)
string description; : base(data)
public object Value {
get { return val; }
}
public Entry(object val, string description)
{ {
this.val = val;
this.description = description;
} }
public override string ToString() public override object Value {
{ get {
return description; object v = base.Value;
if (v == null)
return IsAmbiguous ? null : NullString;
else
return v.ToString();
}
set {
string v = (string)value;
if (v == NullString)
base.Value = null;
else
base.Value = SharedInstances.Box(bool.Parse(v));
}
} }
} }
} }

Loading…
Cancel
Save