gpt4 book ai didi

c# - MVVM 光 "Type Not Found in cache"

转载 作者:太空狗 更新时间:2023-10-29 18:16:06 28 4
gpt4 key购买 nike

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

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

这是我的 View 模型定位器的样子

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"/>

知道我做错了什么吗?

最佳答案

答案是一个相当简单的错误。该位未在设计模式下执行

SimpleIoc.Default.Register<HomePageViewModel>();

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

关于c# - MVVM 光 "Type Not Found in cache",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23591374/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com