WinForms 与视图模型的数据绑定 - 显示视图模型更改的速度很慢

发布于 2024-11-30 20:08:09 字数 553 浏览 0 评论 0原文

我有以下配置...

单个表单,大约有 50-60 个控件(我知道很多)和一个负责存储表单状态的单个视图模型。视图模型属性通过 BindingSource 绑定到表单上的可编辑控件。

我的问题是这样...我希望能够使用按钮清除表单。为了清除表单,我尝试了以下操作:

  • 将 BindingSource 的 DataSource 分配为 null 并重新分配新的视图模型。这最终会严重滞后。
  • 在视图模型中将所有属性设置为 null/空,然后触发 OnPropertyChanged 事件(我的视图模型基类正在实现 INotifyPropertyChanged)。这也严重滞后,而且考虑到我要清除 60 个字段,然后为每个字段触发 OnPropertyChanged 事件,情况确实如此。

那么,有没有一种方法可以修改应用程序,以便它能够清除视图模型并及时反映表单上的更改?我的表单要求所有 50-60 个控件都位于同一表单上,但控件可以分为四个逻辑组。将视图模型分解为四个可以独立处理逻辑组的演示者/视图模型对我来说是否有益?这会影响性能以及反映表单更改所需的时间吗?

谢谢!

I have the following configuration...

Single form with approximately 50-60 controls (it's a lot, I know) and a single view model which is responsible for storing the state of the form. The view model properties are bound to the editable controls on the form via a BindingSource.

My problem is this... I want to be able to clear the form with a button. To clear the form, I have tried the following:

  • Assigning the DataSource of the BindingSource to null and reassigning a new view model. This ends up lagging terribly.
  • Setting all of the properties to null/empty in the view model and then firing the OnPropertyChanged event (my view model base class is implementing INotifyPropertyChanged). This too lags terribly, and it would, given that I'm clearing 60 fields and then firing an OnPropertyChanged event for each one.

So, is there a way I can modify the application so that it is able to clear the view model and reflect the changes on the form in timely fashion? My form requires all 50-60 controls to be on the same form, but the controls could be divided up into four logical groups. Would it be beneficial for me to break up the view model into four presenters/view models that could handle the logical groups independently? Would this impact performance and the time it takes to reflect the changes in the form?

Thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文