未知类型' ViewModelLocator'在XML命名空间' clr-namespace:namespaceblabla; assembly = blabla'

时间:2015-02-19 10:45:35

标签: c# xaml windows-phone-8 mvvm viewmodellocator

我正在建立一个Windows Phone 8.1项目,而我正在使用MVVM Light Libraries库。 我创建了一个PCL项目来保存我的ViewModel,以便以后可以将它们用于Windows Store项目。

我按照指南http://blog.galasoft.ch/posts/2014/04/building-a-universal-application-for-windows-phone-8-1-and-windows-8-1-with-mvvm-light/

进行了操作

但是我在标题中收到了错误?

我的App.xaml

<Application
    x:Class="Roadsmart.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Roadsmart"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="clr-namespace:Roadsmart.Lib.ViewModels;assembly=Roadsmart.Lib"
    mc:Ignorable="d">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/RoadSmartWindowsPhoneStyle.xaml"/>
                <ResourceDictionary Source="Resources/Dictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <viewModels:ViewModelLocator 
                x:Key="Locator"
                d:IsDataSource="True"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>

我在Windows Phone项目中引用了Roadsmart.Lib。 Reference

我的Lib项目属性

Properties of Lib project

然而Blend能够找到我的ViewModel?

Blend Data Binding

但我无法建立,运行。 我也试过清洗。

Error Message

有没有人知道我做错了什么?

提前致谢

1 个答案:

答案 0 :(得分:9)

好的,我通过将App.xaml更改为

来修复它
<Application
    x:Class="Roadsmart.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Roadsmart"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="using:Roadsmart.Lib.ViewModels"
    mc:Ignorable="d">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/RoadSmartWindowsPhoneStyle.xaml"/>
                <ResourceDictionary Source="Resources/Dictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <viewModels:ViewModelLocator 
                x:Key="Locator"
                d:IsDataSource="True"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>