use*_*765 9 wpf mvvm-light portable-class-library
我正在学习使用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.cs有一个底层包,它正在引用该包,并且阻止了它的生成(由于“不存在”,因此又导致了此错误)
因此,在ViewModel / ViewModelLocator.cs中,进行更改
using Microsoft.Practices.ServiceLocation;
至
using CommonServiceLocator;
您的ViewModelLocator和Application驻留在不同的项目中。因此,程序集是不同的,因此您需要在 XAML 定义中提供程序集名称和命名空间名称。
xmlns:vm="clr-namespace:EasyDevis.EasyDevisPCL.ViewModel;assembly=AssemblyName"
打开 PCL 项目的属性并转到应用程序选项卡,您将AssemblyName在那里看到。将该程序集名称替换为AssemblyNameXAML 中的名称。