.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > Good resources for advanced control authoring - where?
Ask a questionAsk a question
 

QuestionGood resources for advanced control authoring - where?

  • Monday, February 05, 2007 4:04 PMceilidhboy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm trying to write a custom control which will support templating in a similar way to an ItemsControl. My control is highly-structured as it presents a fixed hierarchical data set.

    I'd like to be able to support templates for specific lists that I'm displaying, in the same way that an ItemsControl has an ItemTemplate that allows the user of the control to supply the template for only this small part of the control, rather than having to create a complete template for the whole control.

    I'm having problems finding documentation and resources on how to do this, e.g. how does ItemsControl use its ItemTemplate? All the examples I can find about templates show how to *replace* templates on existing controls, rather than how to author a control with this kind of advanced template support.

    Any suggestions on where online I might find this kind of information?

    TIA

All Replies

  • Tuesday, February 13, 2007 7:34 AMKevin Moore - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Answered your question in a blog post: http://blogs.msdn.com/okoboji/archive/2007/02/12/on-itemtemplate-contenttemplate-datatemplate.aspx

    Let me know if this helps.

  • Tuesday, February 13, 2007 12:40 PMSerialSeb Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Kevin,

    very interesting entry. ContentPresenter has the magic to associate an object to the proper datatemplate, or apply a random template, or generate content. But at the end of the road, it's down to DataTemplate.LoadContent()! That's the best way to create your own xxxPresenter in my opinion.

    Get your TemplatedParent from a class called MyItemsPresenter, from there get your DataTemplate from wher eyou need it (and your TemplateSelector if you require one), and generate your content by setting your visual tree to the LoadContent() result?

    The sad thing is that the inheritance chain has been blocked from FrameworkTemplate, so you have to do it that way. It does feel a bit naughty to have to rely on a datatemplate you can't validate as early as you can when your property is of type ItemsPanelTemplate.

    At least that's the path we use here for presenter-like objects in the controls we're developing.