wpftoolkit icon indicating copy to clipboard operation
wpftoolkit copied to clipboard

NumericUpDown: Increment/decrement input stays disabled after moving away from Minimum/Maximum.

Open HerrNyani opened this issue 8 years ago • 3 comments

If the NumericUpDown Value is equal to Minimum, the down key is disabled. If I then press the up key to increment the value, the down key remains disabled, which means that I cannot return to the minimum value by pressing the down key. I can only keep incrementing the value.

The event can be re-enabled by pressing enter or leaving the control first, but I think the increment/decrement enable check should be evaluated whenever the actual value changes when using the up/down keys.

Setting the Value binding to UpdateSourceTrigger=PropertyChanged also doesn't fix the issue.

Tested with IntegerUpDown and DoubleUpDown controls.

EDIT: Using the up and down buttons on the control result in the same behavior.

HerrNyani avatar Jul 13 '18 13:07 HerrNyani

Temporary fix: Whenever the up or down key is released, lose and regain the focus state.

Add to .xaml.cs:

private void NumericUpDown_OnKeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Down || e.Key == Key.Up)
    {
        if (!(sender is UIElement uiElementSender))
        {
            return;
        }

        Keyboard.ClearFocus();
        uiElementSender.Focus();
    }
}

private void NumericUpDown_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
    if (!(sender is UIElement uiElementSender))
    {
        return;
    }

    Keyboard.ClearFocus();
    uiElementSender.Focus();
}

Add to .xaml:

<UserControl.Resources>
    <Style TargetType="xctk:IntegerUpDown" BasedOn="{StaticResource {x:Type xctk:IntegerUpDown}}">
        <EventSetter Event="KeyUp" Handler="NumericUpDown_OnKeyUp" />
        <EventSetter Event="PreviewMouseUp" Handler="NumericUpDown_OnPreviewMouseUp" />
    </Style>
</UserControl.Resources>

Replace IntegerUpDown with the NumericUpDown control you use.

This will only update the control once you release the up or down key. Holding it will delay the check.

Edit: Updated code samples to handle clicking the up and down buttons on the control. Edit 2: Switched to focus reset. Enter event would propagate to containing control, causing side-effects. (ex. DataGrid)

HerrNyani avatar Jul 16 '18 08:07 HerrNyani

Hi, I cannot reproduce this in v3.4. As soon as the up key (or the Up button) is pressed, the down button is enabled. Here's my control : <xctk:IntegerUpDown Value="0" Minimum="0" />

XceedBoucherS avatar Jul 25 '18 14:07 XceedBoucherS

Hello Thanks for checking the issue.

I have found the problem: I misinterpreted the UpdateValueOnEnterKey property as enabling the enter key to input data aside from a focus loss, instead of requiring an enter key press to update the value. Setting the property back to False results in the expected behavior.

My bad, closing this issue.

HerrNyani avatar Jul 26 '18 09:07 HerrNyani