Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不应激发列表的基础对象的InotifyPropertychange事件_C#_List_Inotifypropertychanged - Fatal编程技术网

C# 不应激发列表的基础对象的InotifyPropertychange事件

C# 不应激发列表的基础对象的InotifyPropertychange事件,c#,list,inotifypropertychanged,C#,List,Inotifypropertychanged,我有一个对象,其数据成员已实现INotifypropertychange事件。我想单独维护一个对象列表,其中我不想反映属性更改。如何执行此操作 class MyItem : INPC { public string Name { get { ... } set { this.name = value; raisePropChanged("Name") } } .... } var item = new MyItem(); collection.Add(item); item.Name

我有一个对象,其数据成员已实现INotifypropertychange事件。我想单独维护一个对象列表,其中我不想反映属性更改。如何执行此操作

class MyItem : INPC
{
    public string Name { get { ... } set { this.name = value; raisePropChanged("Name") } } ....
}

var item = new MyItem();
collection.Add(item);

item.Name = "John"; // notifies whoever listens on collection



class MyItemWrapper
{
    private MyItem theBrain;

    public string Name { get{return theBrain.Name;} set{theBrain.Name = value;}}
}

var item = new MyItem();
var wrapped = new MyItemWrapper { theBrain = item };

collectionOne.Add(item);
collectionTwo.Add(wrapped);

item.Name = "John";
// notifies whoever listens on collectionOne
// but whoever listens on collectionTwo will not get any notification
// since "wrapper" does not notify about anything.
// however, since wrapper forwards everything to 'brain':

var name = wrapped.Name; // == "John"

调用函数GetDeepCopy以获取不会引发INPC的对象

公共类验证模型:INotifyPropertyChanged {


简单地说,不要将任何处理程序附加到它们的PropertyChanged事件。否则,您需要重写或修改它们的代码以删除NOI或包装这些项。请您详细说明一下,这是如何做到的?因为我还需要INotify属性更改,我需要借助Observable Collection来处理这些更改。但我还需要在其中保留一个备份列表更改不会得到反映。很抱歉,现在我没有完全理解您想要实现的目标。如果您有一个项目是INPC并且正确实现了INPC,并且如果您将其放入ObsCollection,则ObsColl将附加到项目的PropertyChanged事件,并且在项目的道具发生任何更改时,该项目将发出通知,并发送ObsColl将听到。除非您更改项目的实现方式,或者将ObsCollection更改为哑列表或其他类型,否则您无法阻止这种情况。如果编写类是为了处理事件,它会这样做。如果编写类是为了发出通知,它会这样做。如果您不希望出现这种行为,请使用不同的类来执行您想要的操作。好吧,我将ant从我的可观察的集合中列出一个列表,它不会产生任何INPC。这可能吗?Thx。但是我有一个更好的方法,通过维护一个深度副本来做到这一点。
    private string _validationName;

    public string validationName
    {
        get { return _validationName; }
        set { _validationName = value; NotifyPropertyChanged("ValidationName"); }

    }



    public ValidationModel GetDeepCopy()
    {
        var model = new ValidationModel();

        model.validationName = validationName;

        return model;

    }


    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(string propertyname)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
        }
    }
}