简体   繁体   English

列出要绑定的组合框的字符串

[英]List string to binding combobox

why the combobox items is null, 为什么组合框项目为空,

 <ComboBox ItemsSource="{Binding Path=list}" ......>

so 所以

public List<string> _list = new List<string>();

        public List<string> list
        {
            get
            {
                return _list;
            }
            set 
            {
                _list = value;
            }
        }

and add new item 并添加新项目

while (combodata.Read())
 {
   list.Add(combodata.GetString(0));
 }

I think the need to use INotifyPropertyChanged or DependencyProperty but I do not know how this, please help me people! 我认为需要使用INotifyPropertyChangedDependencyProperty但是我不知道如何使用,请帮助我!

A List does not provide notification when items are added / removed. 添加/删除项目时, List不提供通知。 You need to use a collection class that implements INotifyCollectionChanged . 您需要使用实现INotifyCollectionChanged的集合类。 Try using an ObservableCollection instead: 尝试改用ObservableCollection

public ObservableCollection <string> _list = new ObservableCollection <string>();

使用ObservableCollection <>或在“ while(combodata.Read())”之后引发OnPropertyChanged(“ List”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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