2010-06-29 75 views
0

我遇到问题。我需要在所有文本框中有双格式值WPF TextBox StringFormat不与PropertyChanged一起使用

当您在此输入内容时,在失去焦点后,它将被格式化。

<TextBox Text="{Binding ABC, StringFormat='{}{0:N}'}" /> 

将此UpdateSourceTrigger与propertychanged一起添加时出现问题。那么它将永远不会被格式化。

<TextBox Text="{Binding ABC, UpdateSourceTrigger=PropertyChanged, StringFormat='{}{0:N}'}" /> 

这是为什么?有什么方法可以解决这个问题吗? (在优选XAML)

+0

尝试此 http://stackoverflow.com/questions/3200464/problem-with-updatesourcetrigger-propertychanged-and-stringformat-in-wpf – 2014-06-29 03:48:22

回答

0

尝试此

<TextBox x:Name="test" Text="{Binding MyName, UpdateSourceTrigger=Explicit,StringFormat='{}{0:N}'}" TextChanged="test_TextChanged" Width="100" Height="30" /> 


private void test_TextChanged(object sender, TextChangedEventArgs e) 
    { 
     BindingExpression exp = test.GetBindingExpression(TextBox.TextProperty); 
     exp.UpdateSource(); 
    }