我想读取json并进行迭代以显示数据。但是文本没有样式,将所有数据一起绘制。如何绘制带有样式的文字?
string a = "";
foreach (Messages element in response)
{
a += "<Label Text=\"" + element + " FontSize=\"Large\" HorizontalOptions=\"Center\" VerticalOptions = \"Center\" x: Name = \"lblRes\"";
}
lblRes.Text = a;
写在视图中
<Label Text="Hi" FontSize="Large" HorizontalOptions="Center" VerticalOptions = "Center" x: Name = "lblRes"><Label Text="bye" FontSize="Large" HorizontalOptions="Center" VerticalOptions = "Center" x: Name = "lblRes">
答案 0 :(得分:2)
如果要动态构建一组控件,请将其放置在布局容器中
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);
}