ReactiveUI - 查看定位器性能 [英] ReactiveUI - View Locator performance

查看:341
本文介绍了ReactiveUI - 查看定位器性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WPF 应用程序,它利用 ReactiveUI 中,我发现业绩不佳的地区。

In my WPF application which makes use of ReactiveUI, I've noticed an area of poor performance.

我有一个视图模型里面包含了很多其他的轻量级视图模型(想想30ish)。这些嵌套视图模型简单,一般代表每一个按钮。他们都在用户控件中显示,内部的的ItemsControl 这是使用ReactiveUI的 OneWayBind 接线。这意味着,每个项目在使用显示 ViewModelViewHost

I have a view-model which contains a lot of other lightweight view-models (think 30ish). These nested view-models are simple, usually representing a button each. They're all displayed within a user control, inside an ItemsControl which is wired using ReactiveUI's OneWayBind. This means that each item is displayed using ViewModelViewHost.

在我强大的台式电脑,当我浏览这个视图模型,有一个noticable延迟之间的挤压约0.5秒,去到视图模型按钮,视场改变。当我一个电PC上运行相同的软件,该延迟是近4秒。这是从一个角度UX点一个相当大的问题。

On my powerful desktop PC, when I navigate to this view-model, there is a noticable delay between pressing the "go-to-view-model" button and the view changing, around 0.5 seconds. When I run the same software on a Power-PC, the delay is nearly 4 seconds. This is a pretty big issue from an UX point of view.

我试过分析和调试我的代码很长一段时间,并没有发现问题领域。小人物(注:使用JustMyCode在VS所以ReactiveUI没有露面的)。但是,我没有找到一个方法来消除这个问题。而不是绑定到 ItemsControl.ItemSource OneWayBind ,我这样做是在XAML,因为这样: =的ItemSource绑定{} MyViewModels 并设置的DataTemplate 手动。这将导致更快的转变。

I tried profiling and debugging my code for a long time, and found no problem areas. Zilch (note: using JustMyCode in VS so ReactiveUI didn't show up). I did however, find a way to remove the issue. Instead of binding to the ItemsControl.ItemSource with OneWayBind, I did so in XAML, as such:ItemSource={Binding MyViewModels} and setting the DataTemplate manually. This results in a much quicker transition.

当您使用 OneWayBind 与绑定的ItemsControl ,一个 ViewModelViewHost 将自动为您创建和 ViewLocator 被用于查找查看您的视图模型。我假设这是出于某种原因很慢。

When you bind with OneWayBind with an ItemsControl, a ViewModelViewHost is automatically created for you, and the ViewLocator is used to find the view for your view-model. I'm assuming this is very slow for some reason.

是任何人都知道我怎么能解决这个性能损失,而无需手动定义很多很多的数据模板一个ItemsControl?如果我有视图模型视图模型视图模型,事情往往会变得难看。从我与 Caliburn.Micro 过去的经验,在视图位置约定是非常快,所以如果我不是很用我也想知道 ReactiveUI 正确,并且有另一种方法是更快。

Is anyone aware of how I can get around this performance hit without having to manually define lots and lots of data-templates for an ItemsControl? If I have view-models of view-models of view-models, then things tend to get ugly very quickly. From my past experiences with Caliburn.Micro, the view-location conventions were very quick, so I'm also wondering if I'm not quite using ReactiveUI properly, and that there is an alternative approach which is quicker.

感谢您。

ViewModelViewHost 的DataTemplate 对于〜30视图模式使最初的看法加载时会很慢,而使用户界面看起来好像它已经坠毁。有没有什么办法避免这种情况?

ViewModelViewHost as a DataTemplate for ~30 view-models causes views to be very sluggish when initially loaded, leaving the UI to look as if it has crashed. Is there any way to avoid this?

推荐答案

我相信这个问题的根源是TransitioningContentControl的实现问题。

I believe the root cause of this issue is an implementation issue of TransitioningContentControl.

导航出的内容的当该控制(其中有许多现有的实现所有的地方,其中大部分来自Silverlight的1 AFAICT)将导致额外的加载/卸载的过渡。

This control (which has many existing implementations all over the place, most of which originated from Silverlight one AFAICT) will cause an extra load/unload transition when navigating out of a content.

电流控制将触发卸载/加载/卸载浏览出来的时候,而不是单一的卸载。这个问题在的许多 地方

The current control will trigger Unload/Load/Unload when navigating out, instead of single Unload. This issue is referenced in many places.

当在RxUI使用,这个错误的原因 WhenActivated 在离开查看被调用,从而导致性能问题尤其是,如果当前视图是复杂的。

When used in RxUI, this bug causes WhenActivated to be called on the leaving View, causing performance issues, especially if the current view is complex.

TransitioningContentControl应重新写入,以避免这种额外的过渡,这里的不从这个问题遭受样本实现。

TransitioningContentControl should be re-written to avoid this extra transition, here's an sample implementation which doesn't suffer from this issue.

这篇关于ReactiveUI - 查看定位器性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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