我使用OnPropertyChanged("property");
通过设置属性来引发事件。
Class1.xaml.cs:
public Class1()
{
InitializeComponent();
Class2.PropertyChanged += delegate
{
// do stuff
};
}
在Class2.cs中我有以下内容:
public static event PropertyChangedEventHandler PropertyChanged = delegate { };
public static void OnPropertyChanged(string property)
{
PropertyChanged(null, new PropertyChangedEventArgs(property));
}
Class1中的委托执行一次。 Class2按预期工作。我用断点检查了这个。
按顺序发生的事情是:
Class2触发事件
Class1处理事件
Class2触发事件
Class2触发事件
此外,当我第二次删除= delegate { }
时,处理程序为空。
每次在Class2中触发时,如何处理Class1中的事件?
编辑:
我的项目结构如下:
应用
Class1,主要项目的位置。
App.Shared
Class2的位置,主项目和后台项目的共享逻辑。
App.Background
背景项目
IBackgroundTask
。我在这里打电话给OnPropertyChanged("property")
。