Search code examples
c#windows-phone-8portable-class-library

The tag 'ViewModelLocator' does not exist in XML namespace clr-namespace:XXX


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,


Solution

  • 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