C#TextBox动态显示货币格式

时间:2018-03-19 11:44:51

标签: c# xaml textbox string-formatting currency

我是C#的新人 我通过在网络上搜索答案来尝试几乎一切,但仍然不能自己做。 我的问题是关于格式化文本框

我想要的是当我在文本框中写一个数字时,文本框会显示带有小数和货币符号的数字。

因为我有10个文本框,将数字显示为货币 我明白我必须做有约束力。

对不起我的英文。

这是我的班级转换器

class Bindings : IvalueConverter
{
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
            if (value !=null)
            {
              double valueshop = (double)value;
              return string.Format(culture, "{0:C}", valueshop;
            }
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
     {
           throw new  NotImplementedException();
     }
}

这是我的xaml

<window.Resources>
     <local:Bindings x:Key="ForText"/>
</window.Resources>
<StackPanel Margin="10">
<TextBox Name="MoneyOne" Text="{Binding Converter={StaticResources ForText}, Mode=OneWay, Path=valueshop, UpdateSourceTrigger=PropertyChanged, StringFormat='C'}"/>
    </StackPanel>

我希望有人可以提供帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

您可以尝试:

相关问题