我想創建一個包含數字值文本框的樣式,像這樣:設置的StringFormat返回綁定錯誤
<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 Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'ViewModel.UserControl.vmReceipt' and 'System.String'. Consider using Converter property of Binding. BindingExpression:Path=.; DataItem=vmReceipt' (HashCode=48860040); target element is 'TextBox' (Name=tbNumerical); target property is 'Text' (type 'String')
我該如何解決這個問題?