【问题标题】:How to create a User Interface in Xamarin.Forms using JSON Element如何使用 JSON 元素在 Xamarin.Forms 中创建用户界面
【发布时间】:2017-10-12 03:30:36
【问题描述】:

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

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

【问题讨论】:

  • 你真的有问题吗?仅仅说“我想要 X”并不是在 SO 上提出问题的方式。
  • 我已经更新了问题,你能帮帮我吗?

标签: c# xaml xamarin xamarin.forms xamarin.forms.labs


【解决方案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
}

【讨论】:

  • 感谢杰森的帮助。
  • 我有第二个 Rest API,其中包含我需要填写到上述动态控件中的数据,我如何实现这一点
  • 在开始之前合并列表。或进行第二次传递以添加数据。或者使用数据绑定。有多种方法可以解决它,如果不了解更多细节,很难说哪种方法最有效。
  • 我已经创建了动态控件每个按钮单击它创建重复控件。如何清理控件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 2011-09-08
  • 1970-01-01
  • 2019-03-21
  • 2013-11-21
  • 2013-04-29
  • 1970-01-01
相关资源
最近更新 更多