I need to populate wpf combobox with fixed collection of strings (for example months from january to december).
我需要用固定的字符串集合填充wpf组合框(例如从1月到12月的几个月)。
3 个解决方案
#1
19
In namespace add declaration:
在命名空间添加声明:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
then add combobox where appropriate:
然后在适当的地方添加组合框:
<ComboBox>
<sys:String>January</sys:String>
<sys:String>February</sys:String>
<sys:String>March</sys:String>
...
<sys:String>December</sys:String>
</ComboBox>
#2
4
Like this?
喜欢这个?
<ComboBox >
<ComboBoxItem Content="Jenuary"></ComboBoxItem>
<ComboBoxItem Content="February"></ComboBoxItem>
<ComboBoxItem Content="Mars"></ComboBoxItem>
.... and so on....
</ComboBox>
#3
1
You should bind the ItemsSource
of the combo box to the property of the List<string>.
您应该将组合框的ItemsSource绑定到List
#1
19
In namespace add declaration:
在命名空间添加声明:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
then add combobox where appropriate:
然后在适当的地方添加组合框:
<ComboBox>
<sys:String>January</sys:String>
<sys:String>February</sys:String>
<sys:String>March</sys:String>
...
<sys:String>December</sys:String>
</ComboBox>
#2
4
Like this?
喜欢这个?
<ComboBox >
<ComboBoxItem Content="Jenuary"></ComboBoxItem>
<ComboBoxItem Content="February"></ComboBoxItem>
<ComboBoxItem Content="Mars"></ComboBoxItem>
.... and so on....
</ComboBox>
#3
1
You should bind the ItemsSource
of the combo box to the property of the List<string>.
您应该将组合框的ItemsSource绑定到List