找出 WPF 中 OnPropertyChanged 事件的接收者

Find out the recipients of the OnPropertyChanged event in WPF

我正在对别人编写的项目进行逆向工程。 GUI 是用 WPF 制作的,有几个 windows。一个 class 实现了 INotifyPropertyChanged 接口,2 个属性触发 OnPropertyChanged 事件来通知数据。

我的目的是找出哪个控件从这个事件中获利。当来自 2 个属性的 OnPropertyChanged 事件被触发时,我如何找到所有实际利用信息的控件?

查找委托的所有引用未找到任何结果。没有明确注册此事件。依稀记得在WPF中的XAML代码中可以使用binding来建立这个连接,但是我对WPF了解不够,自己找资料

如有任何帮助,我们将不胜感激

假设您的两个属性分别命名为 FirstPropertySecondProperty。只需在 XAML 中查看对它们的绑定引用,例如:

{Binding FirstProperty}
{Binding FirstProperty, ...}
{Binding [whatever].FirstProperty, ...}
{Binding ..., Path=FirstProperty, ...}
{Binding ..., Path=[whatever].FirstProperty, ...}

使用这些绑定的控件将获得 PropertyChanged 事件。例如,如果您发现:

<TextBlock x:Name="myText", Text="{Binding FirstProperty}" />

这意味着上面的 TextBox 控件将对 PropertyChanged 事件通知的 FirstProperty 更改作出反应。

How can I find all controls that actually harness the information when the OnPropertyChanged event from the 2 properties is fired?

您需要查看所有 XAML 文件,其中实现 INotifyPropertyChanged 接口的 class 可用作具有 {Binding} 一种或另一种方式。在所有文件中搜索 属性 名称可能是最简单的方法。

由于绑定实际上是在运行时解析的,因此没有在编译时找到所有绑定的万无一失的方法。

绑定也可以通过编程方式设置,但您应该能够通过右键单击 属性 并在 Visual Studio 中选择 "Find All References" 来找到这些绑定。