小编use*_*800的帖子

C#Custom CheckBox +自定义绑定数据类型

我创建了自己的复选框(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)

c# user-controls winforms

5
推荐指数
1
解决办法
310
查看次数

标签 统计

c# ×1

user-controls ×1

winforms ×1