none
ItemsControl using multiple panels RRS feed

  • Question

  • Is it possible to create a descendent of ItemsControl that can use multiple panels as ItemsHost and if so what would be the trick?
    Saturday, April 5, 2008 7:06 PM

Answers

  • I don't think you can customize the ItemContainerGenerator, or roll your own invention and hook it up to the ItemsControl. I'd rather take a simple approach, aka place multiple ItemsControls as item container inside a single ItemsControl, and each nested ItemsControl can have a custom ItemsPanel implementation to layout the children placed inside it. Or you can turn on Grouping capability, and apply the custom layout panel to GroupStyle.Panel property.

    Hope this helps
    Tuesday, April 8, 2008 8:23 AM

All replies

  • What you mean by multi panels? do you want to the item container generator to generate items and those items will be put and laid out by different ItemsPanels associated with the ItemsControl? or you just want to dynamically toggle the ItemsPanel to change the layout logic of the ItemsControl?

    Thanks
    Tuesday, April 8, 2008 3:00 AM
  • Yes, I am trying to figure out if it is possible for an item container generator to generate items which should be placed on multiple ItemsPanels associated with the ItemsControl.  I believe I new generator should be made for this, unfortunatly, I can't figure out how to replace the standard generator of an ItemsControl.  Is this possible, or is there another way to achieve this?

    Tuesday, April 8, 2008 7:39 AM
  • I don't think you can customize the ItemContainerGenerator, or roll your own invention and hook it up to the ItemsControl. I'd rather take a simple approach, aka place multiple ItemsControls as item container inside a single ItemsControl, and each nested ItemsControl can have a custom ItemsPanel implementation to layout the children placed inside it. Or you can turn on Grouping capability, and apply the custom layout panel to GroupStyle.Panel property.

    Hope this helps
    Tuesday, April 8, 2008 8:23 AM
  • That's what I was afread of. My current implementation uses a version  of the multiple ItemsControl technique you describe.  My main control inherits from Control and I split up it's sub items over a number of different ItemsControls (property values determin which ItemsControl to use). I unfortunatly don't have the ItemsControl content model, which is very usefull for my control.
    So basically I have 2 options:
    1: Inherit from ItemsControl, as you suggest. For this to work, I think I always need to switch on grouping on my control to get proper layout, since property values determin the ItemsControl to use, not the order of objects or there type (this is correct, right)?
    2: roll out my own ItemsControl look alike version which supports multiple ItemsPanels (ouch). The main difficulty I found regarding this approach is that some key behind the scene actions are done by internal functions (ItemsControl.PrepareContainerForItemOverride, which applies the item template and assigns the content to the container) which are hard and many to reimplement.
    I'm gonna think some more about this.  I will probably blog or something about my final approach.
    Tuesday, April 8, 2008 11:36 AM
  • Have you found a solution to your problem yet?
    I am also needing to implement a control where one collection of items will be displayed in multiple ways for one control.

    Thanks,

    Michael
    Friday, December 5, 2008 5:29 PM