Formatting the Text Property in .NET MAUI XAML

A practical guide on how to format the Text property in .NET MAUI XAML using StringFormat for decimal places and string interpolation, with examples.

  1. One decimal place

    1
    
    <Span Text="{Binding AmbientData.Humidity, StringFormat='{0:N1}'}" TextColor="Black"/>
    
  2. String interpolation

    1
    
    <Label VerticalOptions="Center" Text="{Binding LocalizationResourceManager[LowFlow], StringFormat='{0}:'}"/>
    
    1
    
    <Label Text="{Binding LocalizationResourceManager[ExhalationTime], Mode=OneWay, StringFormat='{0}[s]'}" TextColor="{DynamicResource AxisColor}"/>
    
Built with Hugo
Theme Stack designed by Jimmy