是否需要针对WPF应用程序的特定体系结构解决方案,这些解决方案需要将刷新的数据从模型主动推送到视图? [英] Any specific architectural solution for WPF apps that need to aggressively push refreshed data from Model to View?

查看:93
本文介绍了是否需要针对WPF应用程序的特定体系结构解决方案,这些解决方案需要将刷新的数据从模型主动推送到视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为MVVM和SOLID开发的新手,我正在开发一个小型WPF应用程序,但我意识到我的应用程序在某些方面是非常规的:

Being new at MVVM and SOLID development, I’m working on a small WPF app, and I realized that my app is non-conventional in some ways:

  • 我的所有Model数据都需要通过轮询(每秒一次)或利用回调函数(例如,使用Shell钩子和Automation事件)进行非常频繁的刷新.
  • 所有刷新的数据都需要立即推送到视图".
  • 视图严格是数据的显示;它没有公开任何数据突变功能.
  • All of my Model data needs to be refreshed very often either by polling (every second), or by utilizing callback functions (e.g. with Shell hooks and Automation events).
  • All refreshed data need to be pushed to the View immediately.
  • The View is strictly a display for the data; it doesn't expose any kind of data mutation feature.

当前,我正在使用以下标准MVVM/DataBinding解决方案:

Currently I’m using the following, standard MVVM/DataBinding solution:

  • 我的 Model 类分别实现基于计时器的轮询或设置回调以保持其数据为最新状态,并且它们实现INotifyPropertyChange接口以将所有内容通知订阅者(ViewModel)变化.
  • 我的 ViewModel 订阅了实例化的Model对象的PropertyChanged事件. ViewModel还实现了INotifyPropertyChange接口,当它从Model接收到更改通知时,它会为View发出自己的更改通知. (大多数ViewModel属性只是包装了相同的Model属性,但是最重要的数据(一组项目)被转换为格式化的HTML字符串,以便在View的WebBrowser控件中使用.)
  • 我的 View 照常绑定到ViewModel,并显示更新的数据.
  • My Model classes individually implement timer based polling or set up callbacks to keep their data up-to-date, and they implement the INotifyPropertyChange interface to notify the subscribers (the ViewModel) of all changes.
  • My ViewModel subscribes to the instantiated Model objects’ PropertyChanged event. The ViewModel also implements the INotifyPropertyChange interface, and when it receives change notifications from the Model, it issues its own change notifications for the View. (Most ViewModel properties are simply wrapping the same Model properties, but the most important data, a collection of items, is converted to formatted HTML string to use in the View's WebBrowser control.)
  • My View binds to the ViewModel as usual, and displays the updated data.

该应用程序可以使用此设计,但感觉不正确.

尤其是:

  • 是否建议剪切出ViewModel,并公开所有专门为视图预格式化的Model数据? (没有计划使用这些数据的替代视图.)
  • 是否可以扩展单个基类或实现一个以某种方式有助于集中轮询/回调/变更通知职责的接口?

这是未完成/未完成的模型现在的样子:

您可以大致看到依赖关系的当前状态. (我确信此模型存在很多问题.)

You can roughly see the current state of the dependencies. (I'm sure there are a lot of issues with this model.)

推荐答案

对于简单的数据流只读视图,选择一个好的库也可以帮助您进行体系结构设计.请查看 Rx.Net

For simple read only view of data-streams, choosing a good library can also help you with the architecture design. Please have a look at Rx.Net https://github.com/Reactive-Extensions/Rx.NET You can has a stream of business objects and convert it into a stream of ViewModels and bind the ViewModels to UI.

这篇关于是否需要针对WPF应用程序的特定体系结构解决方案,这些解决方案需要将刷新的数据从模型主动推送到视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆