【发布时间】:2014-04-14 19:07:07
【问题描述】:
我正在使用 MVVM Light 学习 WPF,但我的可移植类库有问题。 我遵循本教程:http://www.codeproject.com/Articles/536494/Portable-MVVM-Light-Move-Your-View-Models
我参考 MVVM Light 创建了一个门户类库和一个 WPF mvvm light 4.5。 我在我的 wpf 项目中添加了我的 PCL 的引用。 所以在我的 PCL 中,我添加了一个文件夹 ModelView 并在我的 ModelViewLocator 中
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using EasyDevis.EasyDevisPCL.Model;
using EasyDevis.EasyDevisPCL.ViewModel.MainPage;
namespace EasyDevis.EasyDevisPCL.ViewModel
{
/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class ViewModelLocator
{
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MainPageViewModel>();
}
/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public MainPageViewModel MainPageViewModel
{
get
{
return ServiceLocator.Current.GetInstance<MainPageViewModel>();
}
}
/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
}
}
}
问题出现在我的 app.xaml 中,并且命名空间是正确的,因为 intelisense 向我建议了路径。
<Application x:Class="EasyDevis.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:EasyDevis.EasyDevisPCL.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="Content/MainPage/View/MainPageView.xaml"
mc:Ignorable="d">
<Application.Resources>
<!--i've the error on this line-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>
</Application>
你知道我做错了什么吗?
【问题讨论】:
-
我怀疑这只是设计时错误。尝试重建解决方案,看看错误是否仍然存在。应用程序运行良好吗?
-
我已经清理并重建了解决方案,但仍然有错误
-
ViewModelLocator 和 Application 是在同一个程序集中还是不同?
-
我在哪里可以检查这个?我有 2 个项目,一个 PCL 和一个 WPF 4.5 MVVM Light
标签: wpf mvvm-light portable-class-library