如何使用 JSON 元素在 Xamarin.Forms 中创建用户界面
How to create a User Interface in Xamarin.Forms using JSON Element
如何使用 JSON 元素在 Xamarin.Forms 中创建用户界面?
我有两个 json 文件,我想使用 Xamarin.Forms.
中的 json 元素创建动态 UI
你可以这样做
StackLayout stack = new StackLayout();
// controls is an collection of control definitions built from your json
foreach(var c in controls)
{
if (c.Type == "Button") {
Button button = new Button();
button.Text = c.Text;
stack.Add(button);
}
if (c.Type == "Label") {
Label label = new Label();
label.Text = c.Text;
stack.Add(label);
}
// repeat for each supported type of control
}
如何使用 JSON 元素在 Xamarin.Forms 中创建用户界面?
我有两个 json 文件,我想使用 Xamarin.Forms.
中的 json 元素创建动态 UI你可以这样做
StackLayout stack = new StackLayout();
// controls is an collection of control definitions built from your json
foreach(var c in controls)
{
if (c.Type == "Button") {
Button button = new Button();
button.Text = c.Text;
stack.Add(button);
}
if (c.Type == "Label") {
Label label = new Label();
label.Text = c.Text;
stack.Add(label);
}
// repeat for each supported type of control
}