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.


I got it when I created a custom (or templated) control that derived from Control (the default) instead of ContentControl.
By: Marc on September 25, 2011
at 2:39 pm