将静态和动态数据添加到组合框wpf

时间:2017-07-02 11:28:53

标签: c# wpf linq combobox

我有一个combobox并且像这样被使用:

XAML

<ComboBox x:Name="cmbMarkOfWatch" 
          Grid.Column="0" Grid.Row="2" 
          Margin="1" 
          Width="230" 
          MaxHeight="20" 
          HorizontalAlignment="Left" />

C sharp

cmbMarkOfWatch.ItemsSource = obj.Clock.Select(w => w.mark).ToArray();
cmbMarkOfWatch.SelectedIndex = 0;

我想在All的顶部添加一个静态值combobox。 我怎么能这样做?

祝你好运

1 个答案:

答案 0 :(得分:1)

尝试,

List<string> results = obj.Clock.Select(w => w.mark).ToList();
results.Insert(0, "All");
cmbMarkOfWatch.ItemsSource = resutls;
cmbMarkOfWatch.SelectedIndex = 0;