将项目添加到ComboBox wpf,它们总是相同的集合?

时间:2015-04-29 20:48:48

标签: wpf xaml

我在我的xaml中声明了一个组合框。 我定义了ExtendedComboBoxItem : ComboBoxItem,它具有属性DisplayName和DisplayImage。

在我的用户控件中,我有一个comboBox控件,我在其中定义了一个基本上是Image | TextBock的数据模板

在代码隐藏中,我总是添加相同的3个项目,所以我做了类似的事情:

List<ExtendedComboBoxItem > items = new List<ExtendedComboBoxItem >();
ExtendedComboBoxItem item1 = new ExtendedComboBoxItem ("A","imagePath");
ExtendedComboBoxItem item2 = new ExtendedComboBoxItem ("A","imagePath");
ExtendedComboBoxItem item3 = new ExtendedComboBoxItem ("A","imagePath");
items.Add(item1);
items.Add(item2);
items.Add(item3);
this.comboBox.ItemsSource = items;

是否有XAML唯一的方法来执行上述操作或更清洁的方法来执行此操作? 谢谢!

0 个答案:

没有答案