私自身のチェックボックス(UserControl)を作成しました。バインディングソースとして機能するControlSourceというプロパティがあります。ただし、ControlSourceのデータ型もカスタム型です。C#カスタムチェックボックス+カスタムバインディングデータ型
...
[System.ComponentModel.Bindable(true), Browsable(true), Category("Behavior")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public IMyBool ControlSource
{
get { return this.chx.Checked ? IMyBool.True : IMyBool.False; }
set { this.chx.Checked = value.Value; }
}
...
、遊ん後、私はここにインタフェース・ソリューションを試してみました:
public interface IMyBool
{
bool Value { get; set; }
IMyBool True { get; }
IMyBool False { get; }
}
public class MyBool
{
protected bool? _bValue = null;
protected string _sTrue = String.Empty;
protected string _sFalse = String.Empty;
protected string _sNull = String.Empty;
public MyBool(bool? bValue = null)
{
this._bValue = bValue;
}
public override string ToString()
{
return this._bValue.HasValue ? (this._bValue.Value ? _sTrue : _sFalse) : _sNull;
}
public bool Value
{
get { return this._bValue.Value; }
set { this._bValue = value; }
}
}
public class MyInvoiceBool : MyBool, IMyBool
{
public static implicit operator MyInvoiceBool(bool? bValue)
{
return bValue.HasValue ? (bValue.Value ? True : False) : Null;
}
public static implicit operator bool?(MyInvoiceBool ivbValue)
{
return ivbValue._bValue;
}
public MyInvoiceBool(bool? bValue = null)
{
base._sTrue = "Rechnung wird gestellt";
base._sFalse = "Rechnung wird nicht gestellt";
base._bValue = bValue;
}
public static MyInvoiceBool True
{
get { return new MyInvoiceBool(true); }
}
public static MyInvoiceBool False
{
get { return new MyInvoiceBool(false); }
}
public static MyInvoiceBool Null
{
get { return new MyInvoiceBool(); }
}
}
public class MyInvoiceAddressBool : MyBool
{
public static implicit operator MyInvoiceAddressBool(bool? bValue)
{
return bValue.HasValue ? (bValue.Value ? True : False) : Null;
}
public static implicit operator bool?(MyInvoiceAddressBool ivbValue)
{
return ivbValue._bValue;
}
public MyInvoiceAddressBool(bool? bValue = null)
{
base._sTrue = "Abweichende Rechnungsadresse";
base._bValue = bValue;
}
public static MyInvoiceAddressBool True
{
get { return new MyInvoiceAddressBool(true); }
}
public static MyInvoiceAddressBool False
{
get { return new MyInvoiceAddressBool(false); }
}
public static MyInvoiceAddressBool Null
{
get { return new MyInvoiceAddressBool(); }
}
}
私の目的は、私は真、偽またはnullのための代替文字列式を知っている私自身のブールデータ型を使用することができるということです。ただし、グループボックスコントロールは一般的にコーディングする必要があります。だからこそ、インターフェイスソリューションが私の心の中に入ったのです。ただし、動作しません。私は、「しばしば使用される」ソリューションがあると確信していますか?