I have two Textbox and I'm trying to add SelectionChanged Event to the two textbox :
TextBox A => Amount
TextBox B => Summary
The scenario is like :
Two Textbox are empty:
The user enter the amount the summary will be equals to
100 * AmountThe user enter the summary after clear the field of amount , he should get
summary / 100in the textbox of amountprivate void Amount_SelectionChanged(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(Amount.Text.ToString())) { Summary.IsReadOnly = true; Summary.Text = (ToDecimalValue(Amount.Text) * 100).ToString(); Amount.IsReadOnly = false; } else { Summary.Text = ""; Summary.IsReadOnly = false; } } private void Summary_SelectionChanged(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(Summary.Text.ToString())) { Amount.IsReadOnly = true; Amount.Text = (ToDecimalValue(Summary.Text) / 100).ToString() Summary.IsReadOnly = false; } else { Summary.Text = ""; Summary.IsReadOnly = false; } }
How can I do this?
I believe there is a simple solution:
Notes:
ToDecimalValue()bydouble.TryParse(), but this will work only if the decimal separator matches that of the application's current culture._and__mean that the parameters are not used.