dimanche 28 juin 2015

Text to Decimal Converter Working but UI not getting updated

I wrote for string to decimal converter and it working fine, the binding is getting updated successfully, however, the GUI is not getting updated.

Example: If I enter "0500" it is getting converted to Decimal value but GUI is not getting updated to 500.

Also, convert back is getting control and not the convert in Iconvert.

My Convert Code:

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
        Dim result As Decimal = 0
        If Decimal.TryParse(value, result) Then
            Return result
        Else
            Return 0
        End If
    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
        If Decimal.TryParse(value, result) Then
            Return result
        Else
            Return 0
        End If
    End Function
End Class

Could you please correct me or advice where I went wrong.

Xaml Code:

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" />

Aucun commentaire:

Enregistrer un commentaire