Reputation: 14310
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" /> <!--> error happens here -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates/Rescources.xaml" x:Name="recources"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
But it give me this error on the marked line:
The name
IocContainer
does not exist in the namespaceusing: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 namespaceclr-namespace:WishLister.Services
.Unknown type
IocContainer
in XML namespaceclr-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?
Upvotes: 2
Views: 592
Reputation: 14310
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 asWishLister.App
you'll need to do some other stuff.
Upvotes: 3