App.xaml 找不到命名空间 IocContainer MVVM
App.xaml can not found namespace IocContainter MVVM
我正在制作一个 windows 10 通用应用程序,采用 MVVM 模式。我将此代码放入 App.xaml 文件中:
<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" /> <!--> error happens here -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates/Rescources.xaml" x:Name="recources"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
但是它在标记的行上给我这个错误:
The name IocContainer
does not exist in the namespace using:WishLister.Services
.
我也尝试在斜体代码中使用 clr-namespace:WishLister.Services
但我遇到了这两个错误:
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
但是我做了一个classWishLister.Services.IocContainer
。这是代码:
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);
}
}
}
这段代码有什么问题?
尝试:
xmlns:services="clr-namespace:WishLister.Services"
我是通过@Will 的评论找到的。他或她说:
- 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.
尝试清理并重建您的项目。
我正在制作一个 windows 10 通用应用程序,采用 MVVM 模式。我将此代码放入 App.xaml 文件中:
<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" /> <!--> error happens here -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates/Rescources.xaml" x:Name="recources"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
但是它在标记的行上给我这个错误:
The name
IocContainer
does not exist in the namespaceusing:WishLister.Services
.
我也尝试在斜体代码中使用 clr-namespace:WishLister.Services
但我遇到了这两个错误:
The name
IocContainer
does not exist in the namespaceclr-namespace:WishLister.Services
.Unknown type
IocContainer
in XML namespaceclr-namespace:WishLister.Services;assembly=WishLister, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
但是我做了一个classWishLister.Services.IocContainer
。这是代码:
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);
}
}
}
这段代码有什么问题?
尝试:
xmlns:services="clr-namespace:WishLister.Services"
我是通过@Will 的评论找到的。他或她说:
- 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 asWishLister.App
you'll need to do some other stuff.
尝试清理并重建您的项目。