2015-10-05 57 views
0

我在我的XAML文件中有组合框。对于它的ItemsSource,我拥有的是一组预定义的值。WPF - ComboBox的ItemsSource具有预定义的值集合

 <ComboBox ItemsSource={Binding MyCollection} 
       SelectedItem={Binding SelectedDataItem} 
       ............../> 

我想知道它是否可以提设定值在WPF本身,而不是硬编码在视图模型。

  <ComboBox ItemsSource={Binding ItemOne,ItemTwo,ItemThree} 
       SelectedItem={Binding SelectedDataItem} 
       ............../> 

有人可以帮忙吗?

回答

0

要么

<ComboBox> 
     <ComboBoxItem>Item1</ComboBoxItem> 
     <ComboBoxItem>Item2</ComboBoxItem> 
     <ComboBoxItem>Item3</ComboBoxItem> 
    </ComboBox> 

或创建数组作为资源,并通过使用StatisResource参考。

+0

我想创建一个数组,然后将其称为StaticResource更好。谢谢 ! –