2015-10-05 56 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更好。謝謝 ! –

相關問題