在MainWindow.xaml.cs中,在InitializeComponent之后添加以下3行:
for (int i = 100; i >= 0; i--)
cboTest.Items.Add(i.ToString());
cboTest.Text = "11";
可以将cboTest.Text设置为显示100到11之间的任何数字,加上0.不显示数字10到1.
如果将循环限制更改为200,则可以显示从200减少到21,加上0.始终是最后10%不显示。
答案 0 :(得分:1)
Microsoft have acknowledged there is a bug in the WPF combobox.
Reason: if the menu items are 100, 99, 98... 0 and you try to set the .Text to 10, the typeahead matches 100 first, finds the strings don't match, and stops.
Workaround: set the .SelectedIndex instead.