MVVM Light“在高速缓存中找不到类型" [英] MVVM Light "Type Not Found in cache"

查看:146
本文介绍了MVVM Light“在高速缓存中找不到类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Windows Phone 8 Silverlight应用程序转换为8.1 Phone应用程序,作为通用应用程序的一部分.我不知道这是否相关,因为这是我第一次尝试正确实现视图模型.我想在Windows和Windows Phone的视图之间共享数据. 无论如何,这是我遇到的错误.

I'm trying to convert my Windows Phone 8 Silverlight application to an 8.1 Phone app as part of a universal app. I don't know if thats relevant because this is the first time I've tried to implement view models correctly. I'd like to share data between views in Windows and Windows Phone. Anyway, this is the error I'm getting.

Error   3   Type not found in cache: ScoreAlerts.ViewModel.FixturesViewModel.   C:\Users\Dave\Documents\Visual Studio 2012\Projects\Score Alerts\ScoreAlerts\ScoreAlerts.WindowsPhone\Pages\Fixtures.xaml   9   5   ScoreAlerts.WindowsPhone
Error   4   Type not found in cache: ScoreAlerts.ViewModel.HomePageViewModel.   C:\Users\Dave\Documents\Visual Studio 2012\Projects\Score Alerts\ScoreAlerts\ScoreAlerts.Shared\Pages\HomePage.xaml 34  9   ScoreAlerts.WindowsPhone

这是我的视图模型定位器的外观

This is how my view model locator looks

public class ViewModelLocator
{
    /// <summary>
    /// Initializes a new instance of the ViewModelLocator class.
    /// </summary>
    public ViewModelLocator()
    {
        if (!ViewModelBase.IsInDesignModeStatic)
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                // Create design time view services and models
                //SimpleIoc.Default.Register<IDataService, DesignDataService>();
            }
            else
            {
                // Create run time view services and models
                //SimpleIoc.Default.Register<IDataService, DataService>();
            }

            SimpleIoc.Default.Register<HomePageViewModel>();
            SimpleIoc.Default.Register<FixturesViewModel>();
        }
    }

    [SuppressMessage("Microsoft.Performance",
        "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
    public HomePageViewModel Main
    {
        get
        {
            //return ServiceLocator.Current.GetInstance<HomePageViewModel>();
            return SimpleIoc.Default.GetInstance<HomePageViewModel>("default");
        }
    }

    [SuppressMessage("Microsoft.Performance",
        "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
    public FixturesViewModel Fixtures
    {
        get
        {
            //return ServiceLocator.Current.GetInstance<FixturesViewModel>();
            return SimpleIoc.Default.GetInstance<FixturesViewModel>("default");
        }
    }

    public static void Cleanup()
    {
        // TODO Clear the ViewModels
    }
}

我的视图XAML拥有

DataContext="{Binding Fixtures, Source={StaticResource Locator}}"

我的应用程序有此

<viewModel:ViewModelLocator x:Key="Locator"
                         d:IsDataSource="True"/>

有什么想法我在做什么错吗?

Any ideas what I'm doing wrong?

推荐答案

答案是一个非常简单的错误.该位未在设计模式下执行

The answer was a fairly simple mistake. This bit was not being executed in design mode

SimpleIoc.Default.Register<HomePageViewModel>();

我的SimpleIoc.Default.Register();代码;包含在从未在设计模式下执行过的if语句中.

My code for SimpleIoc.Default.Register(); was inside an if statement that was never executed in design mode.

这篇关于MVVM Light“在高速缓存中找不到类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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