How to create a custom WPF ContentControl that supports drag-and-drop during development?

I want to create my own WPF control in which there is one “child” control inside. A subclass ContentControleither UserControlworks, but has one drawback: these controls do not work in design mode.

By “not working,” I mean this scenario: suppose I have one Canvaswith my custom control. I want to put, say, Buttoninside 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, Gridor 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?

+3
source share
3 answers

what about inheritance from Border? that way you could get rid of the hassle with a constructor expander

+3
source

I also had a similar question here .

, "" , Content-Control , "HitTestCore" Stephan, drag & drop ContentControl.

Grid Panel ( ) Border ( ).

+1

, , fooobar.com/questions/1317996/....

Just implement the method HitTestCore:

protected override System.Windows.Media.HitTestResult HitTestCore(System.Windows.Media.PointHitTestParameters hitTestParameters)
{
    return new PointHitTestResult(this, hitTestParameters.HitPoint);
}
0
source

Source: https://habr.com/ru/post/1796276/


All Articles