Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Binding Text Value with Converter

$
0
0

Hello,

I'm trying to pass a value from a Entry to a label and doing some maths in between.

I'm using Binding with a Converter :

<Entry x:Name="Number1" Keyboard="Numeric"/>
<Label BindingContext="{x:Reference Number1}" Text="{Binding Text,Converter=DecimalConverter}"/>

`public class DecimalConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return "0";
        decimal thedecimal = (decimal)value+1;
        return thedecimal.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        string strValue = value as string;
        if (string.IsNullOrEmpty(strValue))
            strValue = "0";
        decimal resultdecimal;
        if (decimal.TryParse(strValue, out resultdecimal))
        {
            return (resultdecimal+1);
        }
        return 0;
    }

}`

But the same number entered in the Entry appears.

How can I fix it ?
Is There a simpler way ?

Thank you for your help


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>