使用模型优先方法时是否可以缓存视图? [英] Is it possible to cache the view when using model first approach?

查看:49
本文介绍了使用模型优先方法时是否可以缓存视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的产品中,我们使用 MVVM 模型优先方法,它运行良好,但有一个警告.当视图变得复杂时,从数据模板创建它需要时间.如果视图频繁地显示和隐藏,它会变得有点烦人.如果首先使用视图,那么在需要时缓存视图会很容易——但是当首先使用 DataTemplate 和模型时,我们对视图创建没有太多控制.有人在没有切换到视图优先方法的情况下解决了这个问题吗?

In our product, we use MVVM model first approach and it works nicely but with one caveat. When view becomes complex it takes time to create it from the data template. If the view is shown and hidden frequently, it becomes slightly irritating. If using view first, it would be easy enough to cache a view if needed - but when using DataTemplate and model first, we do not have much control of view creation. Anybody solved this problem already without switching to the view first method?

推荐答案

使用 viewmodel 第一种方法,我认为您没有机会缓存"视图.所以你可以考虑首先使用视图和视图模型定位器来处理重量级的数据模板工作流.此处是将数据模板与列表一起使用时的解决方案.

with viewmodel first approach i think you have no chance to "cache" the view. so you may consider to use view first and a viewmodel locator for the heavyweight datatemplates workflows. here is a solution when using datatemplates with lists.

但也许有任何覆盖 wpf 数据模板机制的解决方案?

but maybe there is any solution with overriding the wpf datatemplate mechanism?

如果您只为您的视图模型创建一个标记视图",那么 wpf 数据模板可以找到它会怎样.然后在这个标记视图中创建/补充真实视图?类似于视图服务定位器?

edit: what if you create just a "markerview" for your viewmodel, so wpf datatemplate can find it. and then within this marker view you create/rehydrate the real view? something like an view service locator?

这篇关于使用模型优先方法时是否可以缓存视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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