如何使用JSON元素在Xamarin.Forms中创建用户界面?
我有两个json文件,我想在Xamarin.Forms中使用json元素创建动态UI。
答案 0 :(得分:1)
你可以做这样的事情
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
}