App.xaml can not found namespace IocContainter MVVM

I'm making a windows 10 universal application whit the MVVM patern. I'm placing this code into the App.xaml file:

<Application
    x:Class="WishLister.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WishLister"
    xmlns:services="using:WishLister.Services"
    RequestedTheme="Light">

    <Application.Resources>

        <ResourceDictionary>        
            <services:IocContainer x:Key="ioc" />

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Templates/Rescources.xaml" x:Name="recources"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

</Application>

but it give me this error on the bold line:

The name IocContainer does not exist in the namespace using:WishLister.Services .

I've also try to use clr-namespace:WishLister.Services in stad of the italic code but I've got these two errors:

The name IocContainer does not exist in the namespace clr-namespace:WishLister.Services .

Unknown type IocContainer in XML namespace clr-namespace:WishLister.Services;assembly=WishLister, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

But I have made a class WishLister.Services.IocContainer . Here is the code:

using GalaSoft.MvvmLight.Ioc;
using WishLister.ViewModels;

namespace WishLister.Services
{
    public class IocContainer
    {
        public IocContainer Ioc
        {
            get
            {
                return App.Current.Resources["ioc"] as IocContainer;
            }
        }

        public MainPageViewModel MainPageViewModel
        {
            get
            {
                return SimpleIoc.Default.GetInstance<MainPageViewModel>();
            }
        }

        public IocContainer()
        {
            SimpleIoc.Default.Register<MainPageViewModel>(false);
        }
    }
}

What's the problem whit this code?


I've found it by a comment of @Will. He or she sayed:

  • Remove <services:IocContainer x:Key="ioc" /> and anything that references the services xmlns.
  • Build your solution.
  • Fix anything preventing this.
  • Then clean, restart Visual Studio, and rebuild.
  • If all is well, try to add your IocContainer into the xaml again.
  • Also, if IocContainer isn't defined in the same assembly as WishLister.App you'll need to do some other stuff.


    尝试:

    xmlns:services="clr-namespace:WishLister.Services"         
    
    链接地址: http://www.djcxy.com/p/5898.html

    上一篇: WPF XAML合并默认名称空间定义

    下一篇: App.xaml找不到名称空间IocContainter MVVM