MvvmCross:ShowViewModel是否总是构造新实例?

前端之家收集整理的这篇文章主要介绍了MvvmCross:ShowViewModel是否总是构造新实例?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每当我调用Showviewmodel时,会以某种方式检索viewmodel和所请求类型的视图,并将它们绑定在一起以在屏幕上显示.何时创建了viewmodel和View的新实例,而不是从某个缓存中查找和检索?如果总是创建新实例并且我选择创建自己的缓存以防止多个实例,那么如何显示我的缓存viewmodel实例?

When are new instances of the viewmodel and View created versus looked up and retrieved from a cache somewhere?

从不 – 对于新导航,默认行为始终是创建新实例.

if… how do I show my cached viewmodel instance?

如果出于某种原因想要覆盖viewmodel位置/创建,那么可以获得有关覆盖App.cs中的DefaultviewmodelLocator的信息:

> MVVMCross Passing values to ViewModel that has 2 constructors
> http://slodge.blogspot.co.uk/2013/01/navigating-between-viewmodels-by-more.html

简而言之,实现您的代码

public class MyviewmodelLocator
  : MvxDefaultviewmodelLocator
{
    public override bool TryLoad(Type viewmodelType,IDictionary<string,string> parameterValueLookup,out IMvxviewmodel model)
    {
        // your implementation
    }
}

然后在App.cs中返回它:

protected override IMvxviewmodelLocator CreateDefaultviewmodelLocator()
{
    return new MyviewmodelLocator();
}

请注意,像How to replace MvxDefaultViewModelLocator in MVVMCross application这样的旧帖子仍然在概念上兼容 – 但这些旧帖子中的详细信息现已过时.

猜你在找的Windows相关文章