I am using the following to selectAll text when the XamCurrencyEditor gets focus, but the cursor is defaulted to the "cents" part of the editor. This results in the SpinButtons adjusting the cents portion of the amount, but i would like it to default to adjust the $ portion instead. When a user focuses the editor with $10.00 displayed, and clicks "UP", I want it to become $11.00, not $10.01. How can I accomplish this?
In XamCurrencyEditor's XAML: GotFocus="XamCurrencyEditorGotFocus"
code-behind:
private void XamCurrencyEditorGotFocus(object sender, RoutedEventArgs e) { XamCurrencyEditor currencyEditor = sender as XamCurrencyEditor; if (currencyEditor != null) { if (!String.IsNullOrEmpty(currencyEditor.Text)) { currencyEditor.SelectAll(); } } }
Hello Travis,
You can try to use the SelectionStart property. You can add this line of code below SelectAll() method:
currencyEditor.SelectionStart = 0;
Hope this will help you.
Regards,
Anastas
That doesn't work for me, as it defeats the purpose of selecting the text to begin with, the user can't just start typing. ie. $750.00, get focus, type 500, get $500,750.00! I thought about using SelectionStart to something like the length minus the cents portion, but that still fouls it up, as the user then tries to type (starting with $750.00) 500.23 and will get $50023.00!! I think I need to somehow make the Spin Increment $1.00 UNLESS the cursor is in the "cents" part, then make it $0.01. That way, if the entire amount is selected, it will replace correctly and get expected results. How to set the Spin Increment when cursor is in "cents" position though?