我正在学习使用MVVM Light和WPF,并且在我的可移植类库中遇到问题。我按照这个教程进行操作:http://www.codeproject.com/Articles/536494/Portable-MVVM-Light-Move-Your-View-Models。
我创建了一个可移植类库和一个WPF mvvm light 4.5,其中引用了MVVM Light。我已经将我的PCL引用添加到我的wpf项目中。因此,在我的PCL中,我已经添加了一个ModelView文件夹,里面包含了我的ModelViewLocator。
我创建了一个可移植类库和一个WPF mvvm light 4.5,其中引用了MVVM Light。我已经将我的PCL引用添加到我的wpf项目中。因此,在我的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文件中,命名空间是正确的,因为智能感知提供了路径建议。<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>
你知道我做错了什么吗?