Skip to content

Commit

Permalink
NumberBox: Fix deselecting text when opening context menu (microsoft/…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Jul 3, 2020
1 parent 8857b72 commit 15a8eaf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ModernWpf.Controls/NumberBox/NumberBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,11 @@ private void StepValue(double change)
}
}

SetCurrentValue(ValueProperty, newVal); ;
SetCurrentValue(ValueProperty, newVal);

// We don't want the caret to move to the front of the text for example when using the up/down arrows
// to change the numberbox value.
MoveCaretToTextEnd();
}
}

Expand All @@ -536,11 +540,7 @@ private void UpdateTextToValue()
try
{
m_textUpdating = true;

SetCurrentValue(TextProperty, newText);

// This places the caret at the end of the text.
m_textBox.Select(newText.Length, 0);
}
finally
{
Expand Down Expand Up @@ -647,6 +647,15 @@ private void UpdateHeaderPresenterState()
}
}

private void MoveCaretToTextEnd()
{
if (m_textBox is { } textBox)
{
// This places the caret at the end of the text.
textBox.Select(textBox.Text.Length, 0);
}
}

bool m_valueUpdating = false;
bool m_textUpdating = false;

Expand Down

0 comments on commit 15a8eaf

Please sign in to comment.