namespace WebSite.Docus.Inputs.CheckBoxs;
class CheckBox1 : BaseComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.Field<CheckBox>("CheckBox1").Set(f => f.Text, "默认").Build();
builder.Field<CheckBox>("CheckBox2").Value("True").Set(f => f.Text, "启用").Build();
builder.Field<CheckBox>("CheckBox3").Enabled(false).Set(f => f.Text, "禁用").Build();
}
}
namespace WebSite.Docus.Inputs.CheckBoxs;
class CheckBox2 : BaseComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
//默认
builder.Field<CheckBox>("CheckBox1")
.Set(f => f.Text, "启用")
.Set(f => f.Switch, true)
.Build();
//开启状态
builder.Field<CheckBox>("CheckBox2").Value("True")
.Set(f => f.Text, "启用")
.Set(f => f.Switch, true)
.Build();
//禁用状态
builder.Field<CheckBox>("CheckBox3").Enabled(false)
.Set(f => f.Text, "禁用")
.Set(f => f.Switch, true)
.Build();
}
}
namespace WebSite.Docus.Inputs.CheckBoxs;
class CheckBox3 : BaseComponent
{
private string? message;
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
//ValueChanged事件
builder.Field<CheckBox>("CheckBox1").ValueChanged(OnValueChanged)
.Set(f => f.Text, "ValueChanged事件")
.Build();
builder.Field<CheckBox>("CheckBox2").ValueChanged(OnValueChanged)
.Set(f => f.Text, "ValueChanged事件")
.Set(f => f.Switch, true)
.Build();
builder.Div("tips", message);
}
private void OnValueChanged(string value)
{
message = value;
StateChanged();
}
}
namespace WebSite.Docus.Inputs.CheckBoxs;
class CheckBox4 : BaseComponent
{
private CheckBox? checkBox;
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.Component<FieldControl>()
.Set(c => c.OnVisibleChanged, OnVisibleChanged)
.Set(c => c.OnEnabledChanged, OnEnabledChanged)
.Set(c => c.OnReadOnlyChanged, OnReadOnlyChanged)
.Set(c => c.SetValue, SetValue)
.Set(c => c.GetValue, GetValue)
.Build();
builder.Field<CheckBox>("CheckBox")
.Set(f => f.Text, "启用")
.Build(value => checkBox = value);
}
private void OnVisibleChanged(bool value) => checkBox?.SetVisible(value);
private void OnEnabledChanged(bool value) => checkBox?.SetEnabled(value);
private void OnReadOnlyChanged(bool value) => checkBox?.SetReadOnly(value);
private void SetValue() => checkBox?.SetValue("True");
private string? GetValue() => checkBox?.Value;
}