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.

Advertisements
Tagged

3 thoughts on “The property ‘_UnknownContent’ does not exist on the type

  1. Marc says:

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

  2. Its such as you read my mind! You appear to know so much approximately
    this, such as you wrote the ebook in it or something.
    I believe that you just could do with some percent to
    drive the message home a little bit, however other
    than that, this is fantastic blog. An excellent read.
    I will definitely be back.

  3. zyzz says:

    The primary benefits you can expect to experience with
    a bodybuilding supplements package are significant increase in lean muscle
    mass, significant increase in strength, improved recovery ability,
    enhanced athletic performance, increased energy & endurance,
    improved protein synthesis & nitrogen retention, and ultimately improved confidence level.
    My Auntie used to say this to me a lot when I started going to the gym at
    16. He’s a man that knows muscle and has some great advice on how to build a body to be reckoned with.

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

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

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

Advertisements
Advertisements
%d bloggers like this: