RubenLancho
RubenLancho

Reputation: 15

Read json and view result in view xamarin

I want to read a json and iterate to show data. But the text does not have style, paint all data together. How can I paint text with style?

string a = ""; 
foreach (Messages element in response)
{
    a += "<Label Text=\"" + element + " FontSize=\"Large\" HorizontalOptions=\"Center\" VerticalOptions = \"Center\" x: Name = \"lblRes\"";
}
lblRes.Text = a;

Write in view

   <Label Text="Hi" FontSize="Large" HorizontalOptions="Center" VerticalOptions = "Center" x: Name = "lblRes"><Label Text="bye" FontSize="Large" HorizontalOptions="Center" VerticalOptions = "Center" x: Name = "lblRes">

Upvotes: 0

Views: 40

Answers (1)

Jason
Jason

Reputation: 89179

if you want to dynamically build a set of controls, place them in a layout container

StackLayout stack = new StackLayout();

foreach (Messages element in response)
{
    Label label = new Label();
    label.Text = element;
    // set Font, LayoutOptions, etc here

    stack.Children.Add(label);
}

Upvotes: 2

Related Questions