How to create a User Interface in Xamarin.Forms using JSON Element

738 views Asked by At

How to create a User Interface in Xamarin.Forms using a JSON Element?

I have two json files and I'd like to create a dynamic UI using json elements in Xamarin.Forms.

1

There are 1 answers

4
Jason On BEST ANSWER

you could do something like this

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
}