Instantiate ItemsPanelTemplate

Posted by Stephan on Stack Overflow See other posts from Stack Overflow or by Stephan
Published on 2010-06-08T14:17:46Z Indexed on 2010/06/08 14:22 UTC
Read the original article Hit count: 251

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight