views:

230

answers:

2

I have a problem. I need to have double formatted values in all TextBoxes.

When you type something into this, after lost focus it will be formatted.

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

Problem arises when you add this UpdateSourceTrigger with propertychanged. Then it will never be formatted.

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

Why is that? Is there any way how to solve that? (in XAML preferably)

A: 

Try this

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

just try Converter

Kishore Kumar