Silverlight – Unable to create an “ObjectName” instance in Designer during use

I tried to bind the combo box item source to a static resource. I over-explained my example, so it’s easy to understand what I’m doing.

< p>So I created a class

public class A: ObservableCollection
{
public A()
{
IKBDomainContext Context = new IKBDomainContext();
Context.Load(Context.GetIBOptionsQuery("2C6C1Q"), p =>
{
foreach (var item in SkinContext.IKBOptions)
{
this.Add(item);
}
}, null);
}
}

Therefore, this class has A constructor that populates itself with the domaincontext that gets data from the persistent database. I just read on this list so I don’t have to worry about sticking to it.

In xaml, I added the name of the class A reference to the space, and then I added it to the page control as usercontrol.resources.



Then I use this staticresource to bind it to my combo box project source.in reality I have to use datatemplate to display this object correctly, but I will not add it here.

Now, when I am a designer, I I get the error:

Unable to create an instance of “A”.

If I compile and run the code, it runs fine. This seems to only affect the xaml page Edit.

What am I doing wrong?

When running in the designer, the full application runtime is not available. However, the designer It’s not just magically knowing how to simulate the UI of a UserControl. Parse its Xaml and instantiate the objects described there.

It’s up to you to write your class to deal with the existence of the designer. You can Use the static proeprty DesignerProperties.IsInDesignTool to determine whether your code is currently used in the designer tool.

If in the designer, you can provide a set of test data instead of trying to access the data service.

p>

I tried to bind the combo box item source to a static resource. I over-explained my example, so it is easy to understand what I am doing.

So I created a class

public class A: ObservableCollection
{
public A()
{
IKBDomainContext Context = new IKBDomainContext();
Context.Load(Context.GetIBOptionsQuery("2C6C1Q"), p =>
{
foreach (var item in SkinContext.IKBOptions)
{
this.Add(item);
}
}, null);
}
}

Therefore, the The class has a constructor, which fills itself with the domaincontext obtained from the persistent database. I just read on this list so I don’t have to worry about sticking to it.

In the xaml I added this class A reference to the namespace, and then I added it to the page control as usercontrol.resources.



Then I use this staticresource to bind it to my combo box project source.in reality I have to use datatemplate to display this object correctly, but I don’t Will be added here.

Now, when I am in the designer, I get the error :

Unable to create an instance of “A”.

If I compile and run the code, it runs normally. This seems to only affect the editing of the xaml page.

What am I doing wrong?

When running in the designer, the full application runtime is not available. However, the designer does not just magically know how to simulate the UI of the UserControl. Parse its Xaml and instantiate the objects described there.

It is up to you to write your class to deal with the existence of the designer. You can use the static proeprty DesignerProperties.IsInDesignTool to determine your code current Whether to use in the designer tool.

If in the designer, you can provide a set of test data instead of trying to access the data service.

Leave a Comment

Your email address will not be published.