这是我的基础界面:
public interface IFlowFunctionType
{
void RefreshAll();
void ClearAll();
}
这是我实现INotifyPropertyChanged的基类:
public class ObservableObject : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Protected Methods
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
这个我的类实现上面的接口:
public class M1 : ObservableObject, ISerializable, IFlowFunctionType
{
public void GetObjectData(SerializationInfo info, StreamingContext context)
{// some code}
public void RefreshAll()
{// some code }
public void ClearAll()
{// some code}
}
请告诉我为什么在 firstInstance 指定 firstInstance firstInstance 的属性时不会激活?
class Main() {
public Main()
{
private M1 firstInstance = new M1();
private M1 secondInstance = new M1();
DeQueue(firstInstance);
}
public void DeQueue( IFlowFunctionType obj)
{
obj= secondInstance ;
obj.RefreshAll();
DbQueues.Remove(firstOrDefault);
}
}
答案 0 :(得分:2)
当您为firstInstance
分配secondInstance
时,M1
的所有属性均未更改。您的对象不知道何时分配它,它只观察它自己的属性。
如果您想观察重新分配,您必须将public class Host : ObservableObject
{
public M1 Instance {get; set;}
}
...
var host = new Host();
host.Instance = new M1();
host.Instance = new M1(); // Reassigned, Host will see the change.
分配给一个本身可观察的对象。
{{1}}