namespace WebSite.Docus.Inputs.RadioLists;
class RadioList1 : BaseComponent
{
private readonly string Codes = "孙膑,后羿,妲己";
private readonly CodeInfo[] Items = new CodeInfo[]
{
new CodeInfo("1", "辅助"),
new CodeInfo("2", "射手"),
new CodeInfo("3", "法师")
};
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
//Codes属性设置列表项
//该值为数据字典类别或逗号分割的字符串
builder.Field<RadioList>("示例1:", "RadioList1").Set(f => f.Codes, Codes).Build();
//Items属性设置列表项
builder.Field<RadioList>("示例2:", "RadioList2").Set(f => f.Items, Items).Build();
//赋值
builder.Field<RadioList>("示例3:", "RadioList3").Value("孙膑").Set(f => f.Codes, Codes).Build();
builder.Field<RadioList>("示例4:", "RadioList4").Value("3").Set(f => f.Items, Items).Build();
builder.Field<RadioList>("平原模式:", "RadioList5").Value("3")
.Set(f => f.IsPlain, true)
.Set(f => f.Items, Items)
.Build();
}
}
namespace WebSite.Docus.Inputs.RadioLists;
class RadioList2 : BaseComponent
{
private RadioList? radioList;
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<RadioList>("英雄:", "RadioList")
.Set(f => f.Codes, "孙膑,后羿,妲己")
.Build(value => radioList = value);
}
private void OnVisibleChanged(bool value) => radioList?.SetVisible(value);
private void OnEnabledChanged(bool value) => radioList?.SetEnabled(value);
private void OnReadOnlyChanged(bool value) => radioList?.SetReadOnly(value);
private void SetValue() => radioList?.SetValue("孙膑");
private string? GetValue() => radioList?.Value;
}