如何将数据绑定到密封类?

发布于 2024-09-14 21:33:30 字数 152 浏览 2 评论 0原文

我正在尝试将一些 WPF 控件绑定到提供给我的密封类。因为它是密封的,所以我无法继承它来创建实现 INotifyPropertyChanged 的​​类。所以我不确定我应该如何去做这件事。我应该创建一个实现 INotifyPropertyChanged 的​​包装器吗?有人知道该怎么做吗?

I'm trying to bind some WPF controls to a sealed class provided to me. Because it is sealed, I cannot inherit from it to create a class that implements INotifyPropertyChanged. So I'm not sure how I should go about doing this. Should I create a wrapper that implements INotifyPropertyChanged? Anyone have any tips on what to do?

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

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

发布评论

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

评论(3

酒儿 2024-09-21 21:33:30

将类包装在提供通知(可能还有验证、编辑支持等)的视图模型中是通常的方法。问题是基础对象是否在流程中的其他地方被修改,如果是,您是否希望这些更改自动反映在 UI 中。如果这样做,您将需要一种更集中的方法 - 通常通过管理这些对象的服务。

Wrapping the class in a view model that provides notification (and maybe validation, editing support etc.) is the usual approach. The question is whether the underlying object is modified elsewhere in your process and, if so, whether you want those changes to be automatically reflected in the UI. If you do, you'll need a more centralized approach - usually by way of a service that manages those objects.

挖个坑埋了你 2024-09-21 21:33:30

如果绑定仅供读取,您可以不实现 INotifyPropertyChanged 而只进行绑定。

If the binding is for reading only you can get away with not implementing INotifyPropertyChanged and just having the binding.

奈何桥上唱咆哮 2024-09-21 21:33:30

嗯,我会用包装纸包裹它。这就像 MVVM 中的方法。 ModelViewModel 包装。

Hmm, I would put a wrapper around it. It's like the approach in MVVM. The Model is wrapped by the ViewModel.

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