2017-04-01 3 views
-1

を結合:設定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')

どうすればこの問題を解決できますか?

答えて

0

スタイルは 'テキスト'のデフォルト値を定義します。しかし、

Text="{Binding Receipt.Amount}" 

あなたのスタイルで定義された 'Text'の値を上書きします。

あなたは問題が「StringFormatは」「テキスト」属性の結合としない特性であるという点である「テキスト」

Text="{Binding Path=Receipt.Amount, StringFormat='#,##0.00;-#,##0.00'}" 

の全体の価値を再定義する必要があります。

関連する問題