C# 标签';ViewModelLocator';XML命名空间clr命名空间中不存在:XXX
我尝试过许多其他的解决方案,但都没有成功。我有一个名为C# 标签';ViewModelLocator';XML命名空间clr命名空间中不存在:XXX,c#,windows-phone-8,portable-class-library,C#,Windows Phone 8,Portable Class Library,我尝试过许多其他的解决方案,但都没有成功。我有一个名为ViewModelLocator的类,它位于我的可移植类库中。它有一个名为ViewModels的属性,类型为Dictionay 然后我有一个WindowsPhone8项目,它引用了可移植类库。我在WP8 app.xaml中添加了以下内容: <Application x:Class="Kaizen.WP8.Test.App" xmlns="http://schemas.microsoft.com/winfx/2006/xa
ViewModelLocator
的类,它位于我的可移植类库中。它有一个名为ViewModels
的属性,类型为Dictionay
然后我有一个WindowsPhone8项目,它引用了可移植类库。我在WP8 app.xaml中添加了以下内容:
<Application
x:Class="Kaizen.WP8.Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:test="clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable">
<Application.Resources>
<test:ViewModelLocator x:Key="ViewModelLocator">
<test:ViewModelLocator.ViewModels>
<test:SampleViewModel x:Key="sampleVM"/>
</test:ViewModelLocator.ViewModels>
</test:ViewModelLocator>
</Application.Resources>
</Application>
我的WP8项目还使用mvvm轻型pcl程序集。我注意到,如果我使用ViewModelBase
类作为字典值,当我得到错误时。这是因为在两个项目之间使用mvvm light pcl存在问题?!
[更新]
非常感谢!!
亲切问候,好的,所以我不确定我在第一次尝试中犯了什么错误,但我重新创建了解决方案,执行了大致相同的步骤,我没有再次收到错误?!o_o我知道这有点晚了,但我在WPF桌面应用程序和控制库方面也遇到了同样的问题。该库的默认目标框架是.Net 4,但在Visual Studio中创建桌面应用程序之后,默认情况下是使用.Net 4客户端配置文件创建的。我将桌面应用程序从.Net 4客户端配置文件更改为.Net 4,它成功了。我刚刚遇到了一个.Net 4.5项目的问题。 我的解决方案是改为.NET4.0,忽略警告,然后改回.NET4.5。 然后问题就解决了 我不知道这对其他人来说是否可行,但对我来说很有效
致意。您是否已经尝试过在构建前进行清理?是否已声明
ViewModelLocator
和SampleViewModel
已公开public
?另外,您的项目是否正确引用了Foo.Core.Portable
dll?您的应用程序可以访问该库吗?@Steve-谢谢您的回复!是的,我不止一次清洁了项目/解决方案。这并没有解决问题。@SuperOli-是的,类和属性都是公共的。您的项目是否正确引用了?你能详细说明一下吗?我通过从参考管理器(解决方案选项卡)中选择项目参考添加了项目参考。是-它是可访问的,它是同一解决方案的一部分。在NuGet Package Manager中,确保MVVMLight、NuGet本身以及可能的系统组成都是最新的。看起来MVVMLight目前可能没有正确处理这个问题。我以前见过类似的问题,迪福为我提供了一个有效的解决方案。这次我很难过。不相关,我只有一个项目。我刚刚重新启动VS,它就消失了。
public class ViewModelLocator
{
public dynamic this[string viewModelName]
{
get
{
if (this.ViewModels.ContainsKey(viewModelName))
{
return this.ViewModels[viewModelName];
}
else
{
return null;
}
}
}
public Dictionary<string, ViewModelBase> ViewModels { get; set; }
public ViewModelLocator()
{
this.ViewModels = new Dictionary<string, ViewModelBase>();
}
}