0

如何使用 JSON 元素在 Xamarin.Forms 中创建用户界面?

我有两个 json 文件,我想在 Xamarin.Forms 中使用 json 元素创建一个动态 UI。

4

1 回答 1

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
}
于 2017-10-12T04:53:17.283 回答