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