我正在尝试将一个预定义的ComboBoxItem添加到已经设置了ItemsSource属性的ComboBox中。例如:
这可以在不修改原始项目集合的情况下实现吗?
(Select item)
Item 1
Item 2
Item 3
这可以在不修改原始项目集合的情况下实现吗?
(Select item)
Item 1
Item 2
Item 3
<ComboBox>
<ComboBox.ItemsSource>
<CompositeCollection>
<ListBoxItem>Please Select</ListBoxItem>
<CollectionContainer Collection="{Binding Source={StaticResource YOURDATASOURCE}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
private ObservableCollection<string> myStrings;
public MyClass()
{
myStrings = new ObservableCollection<string>();
myControl.ItemsSource = myStrings;
}
private void AddNewItem(string item)
{
myStrings.Add(item);
}