I want to create my own WPF control in which there is one “child” control inside. A subclass ContentControl
either UserControl
works, but has one drawback: these controls do not work in design mode.
By “not working,” I mean this scenario: suppose I have one Canvas
with my custom control. I want to put, say, Button
inside my control. I drag it from the toolbar and it appears inside my control. However, the XAML view shows that the new button actually belongs Canvas
, and not to my control.
I can put it in my control by manually editing XAML, but I want the designer to work as well.
Interestingly, when I subclass Canvas
, Grid
or Panel
, the designer works as expected. However, these controls have many children, and this is not what I need.
How can I create a control with one child that works in the designer?
source
share