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
}
}
My view XAML has this
DataContext="{Binding Fixtures, Source={StaticResource Locator}}"
and my app has this
<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>();
My code for SimpleIoc.Default.Register(); was inside an if statement that was never executed in design mode.