@ -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 ) ) ;
}
}
}
}