带有货币的网格视图的单元格



大家好!我有一个问题。 我有一个使用 SQLite 的项目,在 UWP 应用程序中。 我将 db 列表放入 GridView,如何在字段中写一个货币格式的数字(即 5,40 欧元(?

将 db 中的货币字段绑定到 GridView 中的控件(假定为 TextBlock(时,可以使用绑定中的转换器方法来转换货币格式。

转换货币格式时,可以将"C"限定符添加到ToString((方法的格式参数中,如果要显示带有"€"的金额,可以将 ToString 的 xx 参数设置为指向所需的区域性。

下面我简单地使用TextBlock作为示例。

.xaml:

<Page.Resources>
<local:ScenarioBindingConverter x:Key="MyConverter" />
</Page.Resources>
<Grid>
<TextBlock x:Name="MyName" Text="{x:Bind MyPrice,Mode=OneWay,Converter={StaticResource MyConverter}}"></TextBlock>
</Grid>

。.vb:

Namespace Global.AppVB
Partial Public NotInheritable Class MainPage
Inherits Page
Public MyPrice As String
Public Sub New()
Me.InitializeComponent()
MyPrice = "4.5889"
End Sub
End Class

Public Class ScenarioBindingConverter
Implements IValueConverter
Private _DecimalValue As Decimal
Public Function Convert(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.Convert
_DecimalValue = 0D
If value.ToString() > 0 Then
If Not Decimal.TryParse(value.ToString(), System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, _DecimalValue) Then
Else
Return _DecimalValue.ToString("c", System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR"))
End If
End If
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.ConvertBack
Return True
End Function
End Class
End Namespace

最新更新