How do I create a WPF user control with a sub-panel that accepts other controls at design time? I’m trying to write a user control with a toolbar at the top and a panel beneath for “dynamic content”, to add to the toolbox for other devlopers to use.
I’ve done this is Winforms before, but I’ve not been able to figure it out for WPF.
EDIT:
Or am I going at this completely wrong, stuck in Winforms-thinking? I mean, what I want is for users to not having to add the toolbar everytime. Should I instead inherit from, I don’t know, StackPanel and make sure the toolbar alwasys is the upper most control, and have developers add their stuff beneath?
You would write a custom control (not a user control) by deriving from ContentControl. The toolbar at the top would come from the ControlTemplate that you will have to write for your control. Additionally somewhere in your ControlTemplate you would define a ContentPresenter (or alternatively another control with
SomeProperty="{TemplateBinding Content}"). That will be the place where the content (i.e. the UIElement that the user of your control added as a child to an instance of your control) will be displayed.