2010-06-29 8 views
0

J'ai un problème. J'ai besoin d'avoir valeurs double format dans tous les TextBox.WPF TextBox StringFormat ne fonctionne pas avec PropertyChanged

Lorsque vous tapez quelque chose dans ce, après avoir perdu l'accent sera mis en forme.

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

Un problème survient lorsque vous ajoutez ce UpdateSourceTrigger avec propertychanged. Ensuite, il ne sera jamais formaté.

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

Pourquoi est-ce? Est-il possible de résoudre ce problème? (De préférence en XAML)

+0

Essayez cette http://stackoverflow.com/questions/3200464/problem-with-updatesourcetrigger-propertychanged-and-stringformat-in-wpf –

Répondre

0

Essayer ce

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