清单<串GT; INotifyPropertyChanged的事件 [英] List<string> INotifyPropertyChanged event

查看:151
本文介绍了清单<串GT; INotifyPropertyChanged的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串属性和List属性的简单类和我有INofityPropertyChanged事件实现的,但是当我做一。新增的字符串列表此事件是打不到,所以我的转换器,以显示在ListView不击中。我猜属性改变的是打不到一个添加到列表....我怎么能在某种程度上实现此来获取属性更改事件打???



我是否需要使用一些其他类型的集合?!



感谢您的帮助!

 命名空间SVNQui​​ckOpen.Configuration 
{
公共类DatabaseRecord:INotifyPropertyChanged的
{
公共DatabaseRecord()
{
IncludeFolders =新的List<串GT;();
}

#地区INotifyPropertyChanged的会员

公共事件PropertyChangedEventHandler的PropertyChanged;

保护无效的通知(字符串作为propName)
{
如果(this.PropertyChanged!= NULL)
{
的PropertyChanged(这一点,新PropertyChangedEventArgs(作为propName ));
}
}
#endregion

私人字符串_name;

公共字符串名称
{
{返回_name; }


{
this._name =价值;
通知(姓名);
}
}

私人列表<串GT; _includeFolders;

公开名单<串GT; IncludeFolders
{
{返回_includeFolders; }


{
this._includeFolders =价值;
通知(IncludeFolders);
}
}
}
}


解决方案

您应该使用的ObservableCollection<串> 而不是的名单,LT;串> 。而在你的情况下,我会想办法让 _includeFolders 只读 - 你可以随时与集合的一个实例工作



 公共类DatabaseRecord:INotifyPropertyChanged的
{
私人只读的ObservableCollection<串GT; _includeFolders;

公众的ObservableCollection<串GT; IncludeFolders
{
{返回_includeFolders; }
}

公共DatabaseRecord()
{
_includeFolders =新的ObservableCollection<串GT;();
_includeFolders.CollectionChanged + = IncludeFolders_CollectionChanged;
}

私人无效IncludeFolders_CollectionChanged(对象发件人,NotifyCollectionChangedEventArgs E)
{
通知(IncludeFolders);
}



}


I have a simple class with a string property and a List property and I have the INofityPropertyChanged event implemented, but when I do an .Add to the string List this event is not hit so my Converter to display in the ListView is not hit. I am guessing the property changed is not hit for an Add to the List....how can I implement this in a way to get that property changed event hit???

Do I need to use some other type of collection?!

Thanks for any help!

namespace SVNQuickOpen.Configuration
{
    public class DatabaseRecord : INotifyPropertyChanged 
    {
        public DatabaseRecord()
        {
            IncludeFolders = new List<string>();
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void Notify(string propName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
        #endregion

        private string _name;

        public string Name
        {
            get { return _name; }

            set
            {
                this._name = value;
                Notify("Name");
            }
        }

        private List<string> _includeFolders;

        public List<string> IncludeFolders
        {
            get { return _includeFolders; }

            set
            {
                this._includeFolders = value;
                Notify("IncludeFolders");
            }
        }
    }
}

解决方案

You should use ObservableCollection<string> instead of List<string>. And in your case I'd make _includeFolders readonly - you can always work with one instance of the collection.

public class DatabaseRecord : INotifyPropertyChanged 
{
    private readonly ObservableCollection<string> _includeFolders;

    public ObservableCollection<string> IncludeFolders
    {
        get { return _includeFolders; }
    }

    public DatabaseRecord()
    {
        _includeFolders = new ObservableCollection<string>();
        _includeFolders.CollectionChanged += IncludeFolders_CollectionChanged;
    }

    private void IncludeFolders_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        Notify("IncludeFolders");
    }

    ...

}

这篇关于清单&LT;串GT; INotifyPropertyChanged的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆