I'm trying to create a ItemsControl
that has a separator between items, for example a control to create a navigation bread crumb. I want the control to be completely generic.
My original method was to create extend ItemsControl
, add a SeparatorTemplate property, and then have the class add separators to the ItemsHost
of the ItemsControl. The problem with this approach is that if you add extra items to the container panel, the ItemGenerator gets confused and the items are out of order and don't get removed correctly.
So my second plan was to create a completely new control that would emulate an ItemsControl
, but the problem I'm running into is that I can't find a way to instantiate an ItemsPanelTemplate
. I would like to provide an ItemsPanel property just like ItemsControl
, but I can't then create a panel from 开发者_开发问答that template.
Can anyone think of a way to either instantiate an ItemsPanelTemplate
or way to add controls to an ItemsControl
's panel without breaking the ItemGenerator?
Well I haven't tried it myself but I would have thought you would override the GetContainerForItemOverride
to acheive this.
You could create a new BreadCrumbItem
control which is a templated ContentControl
that has in its default template the typical ContentPresenter
and whatever you want to use by default as separator all in a Grid
or StackPanel
.
The GetContainerForItemOverride
generates a new instance of this BreadCrumbItem
sets its ContentTemplate
to the ItemTemplate
property from your ItemsControl
derivative (the BreadCrumb
control?).
Your BreadCrumb
control would also expose BreadCrumbItemStyle
property that you assign to the BreadCrumbItem
you create during GetContainerForItemOverride
.
For completeness you may need to also implement the other *Container*Override
methods in your BreadCrumb
control.
精彩评论