我在MVVM模式下制作了一个Windows 10通用应用程序 . 我将此代码放入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" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates/Rescources.xaml" x:Name="recources"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
但它在粗线上给我这个错误:
命名空间中名称IocContainer不存在:WishLister.Services .
我也尝试在斜体代码中使用 clr-namespace:WishLister.Services
,但我有两个错误:
命名空间clr-namespace中不存在名称IocContainer:WishLister.Services . XML命名空间中的未知类型IocContainer clr-namespace:WishLister.Services; assembly = WishLister,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null
但我已经上了一堂课 WishLister.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);
}
}
}
这段代码有什么问题?
3 回答
尝试:
我是通过@Will的评论找到的 . 他或她说:
尝试清理并重建您的项目 .