嘿,对不起我的英语不好...
我的 sl4 应用程序上有一个非常简单的文本框,如下所示:
<TextBox Text="{Binding Source={StaticResource Valor}, Path=ValorReal, ValidatesOnExceptions=True, Mode=TwoWay, ValidatesOnDataErrors=True, StringFormat=\{0:c\}, NotifyOnValidationError=True}" />
和一个像这样的类:
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));
}
}
}
我住在巴西,所以这里的小数分隔符是“,”,分组数字是“.”,所以 $1.000,50 是一千美元五十美分。
但是使用上面的示例,如果我在文本框中输入 1000,50,则在我退出该字段后它变为 $100,050.00。我如何获得正确的设置?
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator、CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol、CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator具有正确的值,但 silverlight 在我的绑定中忽略了它们 :(
我试着放在
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("pt-BR");
那里,但什么也没发生......