.NET MAUI XAML 格式化技巧:格式化 Text 属性

本指南提供了在 .NET MAUI XAML 中使用 `StringFormat` 格式化控件 `Text` 属性的实用技巧,包括设置小数位数和字符串插值等示例。

  1. 小数点后一位

    1
    
    <Span Text="{Binding AmbientData.Humidity, StringFormat='{0:N1}'}" TextColor="Black"/>
    
  2. 字符串内插

    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