我创建了自己的复选框(UserControl).它有一个名为ControlSource的属性,它作为绑定源.但是,ControlSource的数据类型也是自定义类型.玩完之后,
...
[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; }
}
...
Run Code Online (Sandbox Code Playgroud)
我在这里试过一个接口解决方案
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 …
Run Code Online (Sandbox Code Playgroud)