user2797877
user2797877

Reputation: 135

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

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.

Upvotes: 0

Views: 740

Answers (1)

Jason
Jason

Reputation: 89117

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
}

Upvotes: 1

Related Questions