简体   繁体   中英

System.Controls.ComboBox - How do I get it to add an item that does not exist in its Itemssource?

I have a ComboBox as follows:

  1. Itemssource property is bounded to an ObservableCollection with custom objects (eg items A, B, C).
  2. SelectedItem property is bounded to an object which does not exist in the ItemsSource's bounded collection of objects (eg item D).

I intend to have it exhibit the following behavior:

  1. ComboBox automatically adds the SelectedItem property (in this case, item D) to the bounded ObservableCollection.
  2. ComboBox is shown to have item D selected.

Anybody has any idea on how this can be done using WPF's ComboBox or other components? Any help would be greatly appreciated.

如果您提供更多信息会有所帮助,但通常您必须首先在基础数据源中添加项目D,因为您无法设置ItemsSource并将其他项目添加到ComboBox(或任何其他项目容器)物)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM