我有<Label Text="{Binding Item.O_SALDO , StringFormat = ' {0:N0} '}" TextColor="#006BE6" Font="Bold, 16" Grid.Row="1" HorizontalOptions="End" />
并且我的输出是ex 1,000,000,但我想使用stringformat 1.000.000
有一个实现者的解决方案。
Xaml代码如下:
<Label BackgroundColor="AliceBlue"
Text="{Binding ModelValue}" HorizontalOptions="CenterAndExpand" FontSize="Large" TextColor="Black" />
创建一个将int
值转换为所需格式string
的方法:
private string ConvertIntToFormatSrting(int num)
{
NumberFormatInfo nfi = (NumberFormatInfo)
CultureInfo.InvariantCulture.NumberFormat.Clone();
nfi.NumberGroupSeparator = ".";
string result = number.ToString("N0");
return result;
}
因此在MainPage中:
public string ModelValue { set; get; }
private int number { set; get; }
public MainPage()
{
InitializeComponent();
number = 1000000;
ModelValue = ConvertIntToFormatSrting(number);
Console.WriteLine("------"+ ModelValue);
BindingContext = this;
}
[: