除了数据绑定之外,.NET Framework 中是否使用 INotifyPropertyChanging / Changed?

发布于 2024-07-24 16:45:49 字数 230 浏览 5 评论 0原文

如果你有一个 BindingList例如,您将其绑定到控件,如果您的 Person 类没有实现 INotfiyPropertyChanging / Changed,您对基础 List 的更改将不会自动显示在您的控件中。 我的问题是,就框架而言,这些接口还有其他用途吗? 我不是在谈论使用这些接口来实现基于这些事件的您自己的操作,我是在谈论在 .NET Framework 本身中,是否还需要实现这些接口?

If you have a BindingList<Person> for example and you bind it to a control, if your Person class doesn't implement INotfiyPropertyChanging / Changed, your changes to the underlying List won't show up in your control automatically. My question is, are there any other uses for these interfaces as far as the framework is concerned? I'm not talking about using these interfaces to implement your own actions based on these events, I'm talking about in the .NET Framework itself, is there ever another need to implement these interfaces?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2024-07-31 16:45:49

我不能 100% 自信地说,但由于您没有任何其他答案,而且我自己也很感兴趣,所以我刚刚启动了 Reflector 并检查了哪些类依赖于 INotifyPropertyChanged,简短的答案似乎是:不,它并没有真正用于其他任何用途。

查看这些类,一些非数据绑定引用是:

  • System.Configuration.ApplicationSettingsBase - 因此,如果您决定实现自己的应用程序设置提供程序,那么它应该公开 INPC 功能。 因此,它在 DataBinding 之外的某个领域使用,但范围非常狭窄。

  • System.Printing.PrintTicket 还实现了 INPC。 我没有通过 .NET 进行大量打印,因此这可能很重要,也可能不重要。 我真的不能说。

因此,为了更全面地回答这个问题:如果您不是数据绑定,我怀疑您会发现让您的类实现 INotifyPropertyChanged 有任何好处,有一些边缘情况,该接口在 DataBinding 上下文之外使用,但是如果您如果您在这些领域工作过,您很快就会发现这一点。

I can't speak with 100% confidence, but since you didn't have any other answers and I was interested myself I've just fired up Reflector and checked which classes have a dependency on INotifyPropertyChanged, and the short answer appears to be: No, it isn't really used for anything else.

Looking through the classes, some of the non-databinding references are:

  • System.Configuration.ApplicationSettingsBase - so if you decide to implement your own provider for application settings then it should expose INPC functionality. So there is one area where it is used outside of DataBinding, but a very narrow niche.

  • System.Printing.PrintTicket also implements INPC. I haven't done a great deal of printing through .NET, so this may be important, it may not. I really couldn't say.

So, to answer the question more fully: If you aren't databinding I doubt you'll find any benefit to making your classes implement INotifyPropertyChanged, there are a few edge cases where the interface is used outside of a DataBinding context, but if you were working in those areas you'll quickly find that out for yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文