I want to create custom WPF control that has a single "child" control inside. Subclassing ContentControl
or UserControl
works, but has one flaw: these controls don't work in designer mode.
By "don't work" I mean this scenario: suppose I have a Canvas
with my custom control in it. I want to put, say, a Button
inside my control. I drag it from the toolbox, and it appears inside my control. However, XAML view shows that the new button actually belongs to Canvas
, not to my control.
I can place it inside my control by manually editing XAML, but I want the designer to work too.
Interestingly, when I subclass Canvas
, Grid
or Panel
, designer works as expected. However, these controls have many children, which is not what I need.
How can I make a single-child control that works in designer?