1

Im working on a WPF Custom Control that takes Elements and hides/shows them with a Toggle Button.

The Elements to be hidden should be defined by the User of the Control during Design Time.

The important part of my Control Looks like this:

MyCustomControl.cs

...
 public UIElement InnerContent
    {
        get { return (UIElement)GetValue(InnerContentProperty); }
        set { SetValue(InnerContentProperty, value); }
    }

    public static readonly DependencyProperty InnerContentProperty =
        DependencyProperty.Register("InnerContent", typeof(UIElement), typeof(MyCustomControl));
...

And the corresponding ContentPresenter like this:

<ContentPresenter Height="0"
                  x:Name="ToggleRegion"
                  Content="{Binding Path=InnerContent, RelativeSource={RelativeSource AncestorType=local:MyCustomControl}}">
</ContentPresenter>

My Problem now is it, that i need to make the Height of the ContentPresenter at 0 because i want the Content to be hidden at the Start. Is there a Way i can allow the user of my Control to add Elements by Drag and Drop during his Design Time? This Control should work completly in XAML. The only things defined in Code Behind are the Properties.

Thanks for your help.

Febertson
  • 398
  • 4
  • 23
  • You need to enable AllowDrop property and work from the Drop / DropComplete, drop...etc events. – Michael Puckett II Feb 27 '17 at 22:11
  • Even if i want to allow the User to Drop Elements from the Visual Studio Tools Kit, i Need to implement the Drop Events? – Febertson Mar 01 '17 at 06:22
  • Yes, otherwise it doesn't know how to handle whatever you drop... Plus you may want to change the cursor for items allowed to drop and items not allowed. – Michael Puckett II Mar 03 '17 at 00:04
  • I tried to implement something like that, but im not sure if the Drag/Drop Events are called when the App isn't running. Are those Events called when the App is still in Design Mode? Did you implement something like this before? If yes, have you got a code snippet that might me give a hint how to to detect the important stuff? – Febertson Mar 03 '17 at 06:16
  • Yes I have. I am at work ATM but if you don't get an answer before I have the chance I'll post the code. – Michael Puckett II Mar 03 '17 at 14:25
  • That would be awesome :) – Febertson Mar 07 '17 at 07:43

1 Answers1

0

Even with ContentPresenter not set to 0 height, you won't be able to drag-and-drop UIElements into the control.

See similar questions about drag-and-drop for WPF controls at design time.
WPF - How to enable dragging controls into ContentControl at Design-Time?
How to make custom WPF ContentControl that supports drag-and-drop at design time?

To my opinion there is no any official way to enable Drag-And-Drop during design-time for a Content/UserControl, it's just not supported by design. however you should consider inheriting from Panal, Grid, or Border.

SDP190
  • 336
  • 3
  • 10