Approved
Last Updated: 27 Dec 2016 14:10 by ADMIN
ADMIN
Martin Ivanov
Created on: 18 Jan 2016 17:54
Category: MaskedInput
Type: Bug Report
1
MaskedInput: The Delete button doesn't delete the value when the caret is positioned just before a NumberGroupSeparator
The Delete button doesn't delete the value when the caret is positioned just before a NumberGroupSeparator. This is reproducible only in a no mask scenario with the FormatString property set to a value that allows displaying of the numeric group separators. The controls where the issue appears are RadMaskedNumericInput and RadMaskedCurrencyInput.

Workaround:
Subscribe for the PreviewKeyDown event of the masked input control and if the Delete key is pressed, manually update the value. Here is an example:

void input_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Delete)
    {
        var startIndex = this.input.SelectionStart;
        char character = this.input.Text[startIndex];
        char numbersGroupSeparator = ',';
         
        if (character == numbersGroupSeparator)
        {
            startIndex += 1;
 
            var text = this.input.Text;
            text = text.Remove(startIndex, 1);
 
            var newValue = this.ExractValueFromText(text);
            this.input.Value = double.Parse(newValue);
             
            e.Handled = true;
        }
    }
}
 
private string ExractValueFromText(string text)
{
    string[] splittedText = text.Split(new char[2] { ',', '$' });
    return String.Join("", splittedText);
}
Where the this.input is an instance of a RadMaskedCurrencyInput control defined in XAML. Also, keep in mind that  the Handled property of the event arguments is set to True. Otherwise, the default deletion logic will be triggered and the solution won't work correctly.
0 comments