Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

NumericUpDown: Shouldn't there be a single event for when the user made a change that should be acted upon?

未关闭
#1,750 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp
领域
desktop

调研方向

Start by tracing NumericUpDown's ValueChanged handling, UpdateValueOnEnterKey behavior, and the spinner-related events described in the issue. Clarify the desired event semantics for Enter/Return, focus loss, and completed spinner changes; done means an agreed API that avoids per-keystroke actions while reporting the applied value.

由索引模型根据 Issue 内容生成。

描述

When the user is editing a NumericUpDown, every keystroke raises a ValueChanged event. This is not ideal when it's linked to something that you don't want changed more frequently than necessary. In the past I have dealt with this by handling the KeyUp, LostFocus, and Spinned events like this:

private void TheIntegerUpDown_KeyUp(object sender, KeyEventArgs e)
{
	if (e.Key == Key.Enter || e.Key == Key.Return)
		if (TheIntegerUpDown.Value.HasValue)
			Update(TheIntegerUpDown.Value);
}

private void TheIntegerUpDown_LostFocus(object sender, RoutedEventArgs e)
{
	if (TheIntegerUpDown.Value.HasValue)
		Update(TheIntegerUpDown.Value);
}

private void TheIntegerUpDown_Spinned(object sender, Xceed.Wpf.Toolkit.SpinEventArgs e)
{
	if (TheIntegerUpDown.Value.HasValue && TheIntegerUpDown.Increment.HasValue)
	{
		if (e.Direction == Xceed.Wpf.Toolkit.SpinDirection.Increase)
			Update(TheIntegerUpDown.Value + TheIntegerUpDown.Increment);
		else if (e.Direction == Xceed.Wpf.Toolkit.SpinDirection.Decrease)
			Update(TheIntegerUpDown.Value - TheIntegerUpDown.Increment);
	}
}

This seem like a lot of code to handle something conceptually very simple. I see there is an UpdateValueOnEnterKey property which could simplify this a bit, but when that's set to true, using the up/down spinner buttons no longer raises the ValueChanged event. Furthermore, let's say you needed to look at multiple NumericUpDowns whenever a spinner button on one is used. You would need some mechanism to indicate one particular NumericUpDown's new value, while the others are unchanged.

I can envision a few ways of solving this, if an elegant solution does not exist already:

  • An ActionableValueChanged event (couldn't come up with a better name) that's only raised when the user is typing and hits enter/return, the NumericUpDown loses focus, or a spinner button is pressed.
  • A SpinCompleted event so one can easily get the NumericUpDown's Value after the change has been applied.
主要语言
C#
星标
4.2k
派生
912
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

xceedsoftware/wpftoolkit 的其他 Issue

查看 xceedsoftware/wpftoolkit 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。