开发者

WPF: ComboBox only refreshes to binding when never opened

I have a combobox and set the itemssource to a list of strings:

private List<string> list = new List<string>();
...
ComboBox cbo = new ComboBox();
cbo.ItemsSource = list;

The combobox gets filled successful on startup.

But when the list is changed, the combobox doesn't update its items, BUT only when I expanded the items before, else the combobox gets updated...

Also weird: when I trace the count of items of the combobox, the count is the correct updated number, but the开发者_Go百科 displayed items aren't.

Somebody has an idea, what's going on here?

EDIT: See solution in comments to post of Robert


I guess you need to use ObservableCollection instead of List, because ComboBox needs to be notified whenever the collecion changes.


Change List into ObservableCollection.


Use ObservalbeCollection. It has inbuilt mechanism to notify and change in the number of items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜