问题
I have tried numerous other solutions without any success. I have a class called ViewModelLocator
which is located in my portable class library. It has a property in it called ViewModels
, which is of type Dictionay<K, V>
Then I have a Windows Phone 8 project that references the portable class library. I added the following to the 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>
When I press F12 on the tags, it navigates to the correct class and or property in my pcl. Which indicates that VS knows about the objects, but when I try and build, I receive the following error:
The tag 'ViewModelLocator' does not exist in XML namespace 'clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable'.
The tag 'SampleViewModel' does not exist in XML namespace 'clr-namespace:Foo.Core.Portable.ViewModel;assembly=Foo.Core.Portable'.
Could anyone please provide some assistance?
[Update]
I reference the pcl version of mvvm light in my pcl project. This is how the ViewModelLocator
class looks like:
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>();
}
}
My WP8 project also makes use of the mvvm light pcl assemblies. I noticed that, if I make use of the ViewModelBase
class as the dictionary value, that when I get the errors. It's as there's an issue using the mvvm light pcl between the two projects?!
[Update]
Many thanks in advance!! Kind regards,
回答1:
I just had this problem with a .Net 4.5 project. The solution for me was to change to .Net 4.0, ignore the warnings, and change back to .Net 4.5. Then the problem was gone.
Don't know if it is a feasible way for others, but it worked for me.
Best regards.
回答2:
Okay, so I'm not exactly sure what I did wrong in my first attempt, but I recreated the solution and performed more or less the same steps and I didn't receive the error again?! o_O
回答3:
I know this is a bit late but I had the same problem with a WPF Desktop app and a control library. The library's default Target Framework was .Net 4 but the Desktop app just after I created in in Visual Studio was by default created with .Net 4 client profile. I changed the Desktop app from .Net 4 client profile to .Net 4 and it worked.
来源:https://stackoverflow.com/questions/18257660/the-tag-viewmodellocator-does-not-exist-in-xml-namespace-clr-namespacexxx