views:

411

answers:

1

Hey, sorry for my bad english...

I have a very simple textbox on my sl4 app, like this:

<TextBox Text="{Binding Source={StaticResource Valor}, Path=ValorReal, ValidatesOnExceptions=True, Mode=TwoWay, ValidatesOnDataErrors=True, StringFormat=\{0:c\}, NotifyOnValidationError=True}" />

and a class like:

public class Valor: INotifyPropertyChanged
{
    double _valorReal;
    public double ValorReal
    {
        get
        {
            return _valorReal;
        }
        set
        {
            _valorReal = value;
            RaisePropertyChanged("ValorReal");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
}

I live in Brazil, so here the decimal separator is "," and the grouping digit is ".", so $1.000,50 is one thousand dollars and fifty cents.

But using the sample above, if i digit 1000,50 on the textbox, after i exit the field it turns to $100,050.00. How do i get the correct settings?

The CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol, CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator have the right values but silverlight is ignoring them on my binding :(

I tried to put System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("pt-BR"); there but, nothing happen...

A: 

You don't need to include the {0:} in the format string.

{Binding Source={StaticResource Valor}, Path=ValorReal, ValidatesOnExceptions=True, Mode=TwoWay, ValidatesOnDataErrors=True, StringFormat=c, NotifyOnValidationError=True}
Stephan