Proper design for custom templated parent/child control?  
Author Message
Bill Henning





PostPosted: Windows Presentation Foundation (WPF), Proper design for custom templated parent/child control? Top

Hi everyone, I'm looking for some pointers on building a custom control. I'm doing this as an exercise in learning WPF. Basically here are my requirements:

1) Will have a parent control (ParentControl class) that has a specific Type of child items (ChildPane class).
2) The ParentControl class needs to host the child panes in a certain area. Then it might also have a header area.
3) Only one ChildPane will be visible at a time in the ParentControl.
4) The ChildPane class should be capable of hosting custom content.
5) Both controls need global default styles/templates to be set.
6) For each control, the end user should be able to set a style/template that overrides the global default set up by me for both controls.
7) The end user should be able to set a style/template on a specific ParentControl instance that overrides any global default style/template for ParentControl.
8) The end user should be able to set a style/template on a specific ParentControl instance that overrides the global default style/template for the ChildPane objects displayed in the ParentControl.
9) The end user should be able to set a style/template on a specific ChildPane instance that overrides both the global default style/template for ChildPane AND the style/template, if any, that is set on the "parent" ParentControl for its ChildPanes.

Usage should be simple like this:

<controls:ParentControl>
<controls:ChildPane>Pane #1</controls:ChildPane>
<controls:ChildPane>Pane #2</controls:ChildPane>
<controls:ChildPane>Pane #3</controls:ChildPane>
</controls:ParentControl>

Does anyone have any recommendations on getting this sort of functionality working, like a sample that is already out in the wild I've seen samples that do some of this but not all of it.

Also, these are preferred...
1) The parent control's Items collection only return ChildPane types so no casting is needed for the end user.
2) The SelectedPane property should get/set a ChildPane and update UI appropriate when set.

I am considering using Selector as a base class for the ParentControl but that will mean that my Items will be generic and I would prefer them not to be. I am considering ContentControl as my ChildPane base class.

Any help or sample code for the design principles above to get me started is appreciated.




Visual Studio 200826