I m using the binding in Silverlight. I have binded the TextBox with Decimal entity. Below is the Code snipts of bindings.
<TextBox x:Name="AmountBox" Text="{Binding SelectedEntity.Amount,Mode=TwoWay,StringFormat=\{0:n2\},Converter={StaticResource DecimalBlankValueConverter}}" Validate="True" TextChanged="AmountBox_TextChanged" LostFocus="AmountBox_LostFocus"/>
Below is the converter code.
decimal result;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!Decimal.TryParse(value.ToString(),out result) || (decimal)value == decimal.Zero)
return null;
return decimal.Parse(value.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || !Decimal.TryParse(value.ToString(), out result))
return 0.00;
return decimal.Parse(value.ToString());
}
on lost focus I am updating the source with GetBindingExpression(TextBox.TextProperty).UpdateSource();
Everything is workig well, But convert is not called on lost focus and when I am entering string in the textbox, than convert is not called and it will not convert the textBox text to blank.
Can anyone please suggest me , what is the probelm in the code.
Thanks in advance. ----Raj