Error Cannot create an Instance of "ObjectName" in Designer when using <UserControl.Resources>
- by Mike Bynum
Hi All,
I'm tryihg to bind a combobox item source to a static resource. I'm oversimplfying my example so that it's easy to understand what i'm doing.
So I have created a class
public class A : ObservableCollection<string>
{
public A()
{
IKBDomainContext Context = new IKBDomainContext();
Context.Load(Context.GetIBOptionsQuery("2C6C1Q"), p =>
{
foreach (var item in SkinContext.IKBOptions)
{
this.Add(item);
}
}, null);
}
}
So the class has a constructor that populates itself using a domaincontext that gets data from a persisted database. I'm only doing reads on this list so dont have to worry about persisting back.
in xaml i add a reference to the namespace of this class then I add it as a usercontrol.resources to the page control.
<UserControl.Resources>
<This:A x:Key="A"/>
</UserControl.Resources>
and then i use it this staticresource to bind it to my combobox items source.in reality i have to use a datatemplate to display this object properly but i wont add that here.
<Combobox ItemsSource="{StaticResource A}"/>
Now when I'm in the designer I get the error:
Cannot Create an Instance of "A".
If i compile and run the code, it runs just fine. This seems to only affect the editing of the xaml page.
What am I doing wrong?