Posted by: beatkiener | August 28, 2009

The property ‘_UnknownContent’ does not exist on the type

Today I was working on a custom control. I had it all coded up, but when I went to build a XAML fragment which uses the control, it gave me the following two errors:

The property ‘_UnknownContent’ does not exist on the type ‘AnimatedPanel’ in the XML namespace ‘clr-namespace:Nova.Toolkit;assembly=Nova.Toolkit’.

Unfortunately this error message in not a very helpful.  I’m embarrassed to say how long it took me to figure out the problem, so I’m not going to tell you. 
But I will tell you how to solve this if you run into it.

 

My custom control directly inherits from control, because the content should be a list of items and not just one UIElement (not important here…).

public class AnimatedPanel : Control
{
    public ObservableCollection<UIElement> Children { get; private set; }
}

 

The error only arises when the XAML parser has to parse my custom control (like the following)

<toolkit:AnimatedPanel >
   <Border />
   <Border />
   <Border />
</toolkit:AnimatedPanel >

It’s surprisingly simple to fix the error above: I forgot to declare the content property on the AnimatedPanel as following:

[ContentProperty("Children")]
public class AnimatedPanel : Control
{
    public ObservableCollection<UIElement> Children { get; private set; }
}

This tells the XAML reader to which property to put the child elements.

That’s all.

Advertisement

Responses

  1. I got it when I created a custom (or templated) control that derived from Control (the default) instead of ContentControl.


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.