In my NET8
MAUI
project, I want to display a list of text with the properties. For example, I get this class to define the chunk of a phrase I want to dislay
public class FormattedText
{
public FontAttributes FontAttributes { get; set; } = FontAttributes.None;
public string? Text { get; set; }
public Color TextColor { get; set; } = Colors.Black;
}
then, I have
public IList<FormattedText>? FormattedText { get; set; }
and then I pass FormattedText
in the following code
<FlexLayout
AlignItems="Start"
BindableLayout.ItemsSource="{Binding FormattedText}"
Direction="Column"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label
Padding="10"
FontAttributes="{Binding FontAttributes}"
Text="{Binding Text}"
TextColor="{Binding TextColor}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
As a result of this code, I get this output
Because this should form a proper phrase, I changed to this
<FlexLayout
AlignItems="Start"
BindableLayout.ItemsSource="{Binding FormattedText}"
Direction="Row"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label
Padding="10"
FontAttributes="{Binding FontAttributes}"
Text="{Binding Text}"
TextColor="{Binding TextColor}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
but the output is not correct
What is it wrong?