我尝试了许多其他解决方案,但都没有成功。我有一个名为的类ViewModelLocator
,它位于我的可移植类库中。它有一个名为 的属性,它ViewModels
的类型是Dictionay<K, V>
然后我有一个引用可移植类库的 Windows Phone 8 项目。我在 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>
当我在标签上按 F12 时,它会导航到我的 pcl 中正确的类和/或属性。这表明 VS 知道对象,但是当我尝试构建时,我收到以下错误:
XML 命名空间“clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable”中不存在标记“ViewModelLocator”。
XML 命名空间“clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable”中不存在标记“SampleViewModel”。
有人可以提供一些帮助吗?
[更新]
我在我的 pcl 项目中引用了 mvvm light 的 pcl 版本。这是ViewModelLocator
类的样子:
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>();
}
}
我的 WP8 项目也使用了 mvvm light pcl 程序集。我注意到,如果我将ViewModelBase
类用作字典值,那么当我得到错误时。这是因为在两个项目之间使用 mvvm light pcl 有问题吗?!
[更新]
提前谢谢了!!亲切的问候,