我写了一个字符串到十进制转换器,它工作正常,绑定成功更新,但是,GUI没有得到更新 - 这是针对Windows Phone 8.1 - winrt如果我是对的。
示例:如果我输入" 0500"它将转换为十进制值,但GUI未更新为500。
此外,转换回来是控制而不是Iconvert中的转换。
我的转换代码:
nvm alias default <version>
请你纠正我或建议我哪里出错了。
Xaml代码:
Public Class DecimalConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.Convert
Return value.ToString
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.ConvertBack
Dim result As Decimal = 0
Decimal.TryParse(value, result)
Return result
End Function
End Class
输出:
编辑: 绑定类的代码。
xmlns:cn="using:MCPhone81.MCCommonCodes.Converters"
<Page.Resources>
<cn:VisibilityConverter x:Name="VisConvert"/>
<cn:DecimalConverter x:Name="DecConverter"/>
</Page.Resources>
<TextBox Text="{Binding Obj.Amount, Mode=TwoWay, Converter={StaticResource DecConverter}}" Grid.Row="2" Grid.Column="0" MinWidth="220" InputScope="Number" />
编辑:在UI上绑定数据
Public Class SimpleReceipt
Inherits BaseClass
Private _CollectionAmountValue As Decimal
Property CollectionAmount As Decimal
Get
Return _CollectionAmountValue
End Get
Set(value As Decimal)
If Not _CollectionAmountValue = value Then
_CollectionAmountValue = value
NotifyPropertyChanged("CollectionAmount")
End If
End Set
End Property
End Class
Public Class BaseClass
Implements ComponentModel.INotifyPropertyChanged
Public Event PropertyChanged(sender As Object, e As ComponentModel.PropertyChangedEventArgs) Implements ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub NotifyPropertyChanged(ByVal PropertyName As String)
RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs(PropertyName))
End Sub
End Class