We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
扩展 WPF 工具包有一个: NumericUpDown
The Extended WPF Toolkit has one: NumericUpDown
原始 WPF 控件集中缺少但经常使用的控件是 NumericUpDown 控件。 这是一种让用户在小区域内从固定范围中选择数字的巧妙方法。 可以使用滑块,但对于水平空间很小的紧凑表单,NumericUpDown 是必不可少的。
解决方案 A(通过 WindowsFormsHost)
您可以通过将 Windows 窗体 NumericUpDown 控件托管在 WindowsFormsHost 中来使用 WPF 中的控件。 请注意,您必须包含对 System.Windows.Forms.dll 程序集的引用。
解决方案 B(自定义)
有多个商业版本和 codeplex 版本,但都涉及安装第 3 方 dll 和项目的开销。 构建自己的滚动条要简单得多,一种简单的方法是使用 ScrollBar。
事实上,没有 Thumb(只有中继器按钮)的垂直 ScrollBar 正是我们想要的。 它继承了RangeBase,因此它具有我们需要的所有属性,例如Min、Max和SmallChange(设置为1,以将其限制为整数值)
因此我们更改ScrollBar ControlTemplate。 首先,我们删除拇指和水平触发操作。 然后,我们将剩余的内容分组到网格中,并为数字添加 TextBlock:
来源:
A control that is missing from the original set of WPF controls, but much used, is the NumericUpDown control. It is a neat way to get users to select a number from a fixed range, in a small area. A slider could be used, but for compact forms with little horizontal real-estate, the NumericUpDown is essential.
Solution A (via WindowsFormsHost)
You can use the Windows Forms NumericUpDown control in WPF by hosting it in a WindowsFormsHost. Pay attention that you have to include a reference to System.Windows.Forms.dll assembly.
Solution B (custom)
There are several commercial and codeplex versions around, but both involve installing 3rd party dlls and overheads to your project. Far simpler to build your own, and a aimple way to do that is with the ScrollBar.
A vertical ScrollBar with no Thumb (just the repeater buttons) is in fact just what we want. It inherits rom RangeBase, so it has all the properties we need, like Min, Max, and SmallChange (set to 1, to restrict it to Integer values)
So we change the ScrollBar ControlTemplate. First we remove the Thumb and Horizontal trigger actions. Then we group the remains into a grid and add a TextBlock for the number:
Sources:
如果商业解决方案没问题,你可以考虑这个控制集:
Mindscape 的 WPF Elements
它包含这样一个旋转控件,或者(我个人的偏好)一个spin-decorator,可以在 XAML 中装饰各种数字控件(例如 IntegerTextBox、NumericTextBox,也是控件集的一部分),如下所示:
If commercial solutions are ok, you may consider this control set:
WPF Elements by Mindscape
It contains such a spin control and alternatively (my personal preference) a spin-decorator, that can decorate various numeric controls (like IntegerTextBox, NumericTextBox, also part of the control set) in XAML like this:
添加文本框和滚动条
在VB中
add a textbox and scrollbar
in VB