简体   繁体   English

ListBox作为WPF中的数字UpDown控件

[英]ListBox as Numeric UpDown control in WPF

One of the disadventage I found in WPF is it doesnot have a Numeric UpDown control. 我在WPF中发现的缺点之一是它没有Numeric UpDown控件。 So I make a listbox with height as 25 so that it will display only one item at a time and the vertical scroll feels like a UpDown controls. 因此,我制作了一个高度为25的列表框,使其一次仅显示一个项目,并且垂直滚动感觉就像一个UpDown控件。 My problem is when I use the scroll to change the value, I can't get the current value shown in listbox. 我的问题是,当我使用滚动条更改值时,无法获得列表框中显示的当前值。 Can any idea to get the value shown in listbox without selecting it? 是否有任何想法可以在不选择它的情况下获取显示在列表框中的值?

The Extented WPF Toolkit has one: NumericUpDown 扩展的WPF工具包具有一个: NumericUpDown 在此处输入图片说明

尽管没有标准的WPF NumericUpDown,但是您可以尝试使用带有主题和UI自动化支持示例的NumericUpDown自定义控件

well since you are using WPF, you can change the template of your ListBoxItem and change it's look to nothing when the item is selected ( i mean remove the trigger ), that's all. 很好,因为您正在使用WPF,所以可以更改ListBoxItem的模板,并在选择该项目时将其外观更改为空白(我的意思是删除触发器),仅此而已。
I hope it's helpful, unless you need other things than this. 我希望它会有所帮助,除非您需要除此以外的其他功能。

You can also attach a ScrollBar.Scroll event. 您还可以附加ScrollBar.Scroll事件。 This fires when you scroll. 滚动时触发。 Maybe you can then change the SelectedIndex manually or set the focus? 也许您可以随后手动更改SelectedIndex或设置焦点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM