views:

31

answers:

1

What controls are there to inherit from that has the property of Children and supports templating when building a custom usercontrol.

Currently I know about Panel, but it does not support properties and methods like DefaultStyleKey and GetTemplateChild();

Is there an interface that I can inherit from for templates such as:

public class Scroller : Panel, ITemplates //Something like ITemplates
{
   public override void OnApplyTemplate()
   {
        base.OnApplyTemplate();
        container = GetTemplateChild("container") as StackPanel; //I want to be able to do this

        this.Children; //And also be able to use this
   }
}
+1  A: 

You want ItemsControl. It has an Items property and its template is very flexible as demonstrated by the fact that TabControl, ListBox, ComboBox, etc all derive from it.

Josh Einstein
For some reason, thats what was there before but it would not work. I going to be using my custom control inside an ItemsPanelTemplate for a listbox. When I inherit from ItemsControl, it tells me that I need a root of Panel.
Shawn Mclean
Correct, if you are trying to override layout of a ListBox then you have to create a Panel and you don't get a template. A panel has no visual representation, it simply lays out its children and thus there is no need for a template.
Josh Einstein
You should instead decide if you want to create a custom ItemsControl (in other words, no ListBox) or if you just want to override the layout of a ListBox.
Josh Einstein
I think I'll use it as a custom ItemsControl. Like how ListBox items are called ListItems, what do I call the items for this control? I'll be attaching a Generated Items Template to it and bind it to an ItemSource.
Shawn Mclean