2010-06-29 1 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 –

답변

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(); 
    }