C# 在xaml样式中设置StringFormat返回绑定错误

C# 在xaml样式中设置StringFormat返回绑定错误,c#,wpf,xaml,data-binding,C#,Wpf,Xaml,Data Binding,我想为包含数值的文本框创建一种样式,如下所示: <Style x:Key="MoneyTextbox" TargetType="{x:Type TextBox}"> <Setter Property="Height" Value="20"/> <Setter Property="Margin" Value="10,5,10,5" /> <Setter Property="VerticalAlignment" Value="Cent

我想为包含数值的文本框创建一种样式,如下所示:

<Style x:Key="MoneyTextbox" TargetType="{x:Type TextBox}">
    <Setter Property="Height" Value="20"/>
    <Setter Property="Margin" Value="10,5,10,5" />
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="HorizontalContentAlignment" Value="Right"/>
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Text" Value="{Binding Path=., StringFormat='#,##0.00;-#,##0.00'}" />
</Style>

我使用的样式如下:

<TextBox x:Name="tbNumerical" Text="{Binding Receipt.Amount}" Style="{StaticResource MoneyTextbox}" Grid.Column="0"/>

但返回以下错误:

System.Windows.Data错误:1:无法创建到的默认转换器 在类型之间执行“双向”转换 “ViewModel.UserControl.vmReceipt”和“System.String”。考虑使用 绑定的转换器属性。BindingExpression:Path=。; DataItem=VMReceive'(HashCode=48860040);目标元素是“TextBox” (名称=待定数字);目标属性为“Text”(类型为“String”)


如何修复此问题?

样式定义了“Text”的默认值。但是通过

Text="{Binding Receipt.Amount}"
您可以覆盖由样式定义的“文本”的值

您必须重新定义“文本”的整个值

Text="{Binding Path=Receipt.Amount, StringFormat='#,##0.00;-#,##0.00'}" 
问题是“StringFormat”是绑定的属性,而不是“Text”属性