What exactly does Panel.IsItemsHost do?

前端 未结 3 1011
醉酒成梦
醉酒成梦 2020-12-25 10:30

What does the Panel.IstItemsHost attached property used for?

I see plenty of examples of people setting it on the ItemsContainer template for an ItemsCo

3条回答
  •  鱼传尺愫
    2020-12-25 11:34

    Say I have an ItemsControl. I want to use a custom panel that swoops items in and out as you scroll; its called a SwoopPanel. Now, how do I tell the ItemsControl to use my SwoopPanel to contain the templates it creates?

    The quick way is to set the ItemsPanel on the ItemsControl:

    
        
          
        
    
    

    However, sometimes that doesn't work for you. Maybe you wish to customize how the SwoopPanel is presented in the UI, and the only way to get around this is to change the control template of the ItemsControl. Now you can add your SwoopPanel directly to the control template and, using the property, mark it as the ItemsHost that the ItemsControl will put all the templated items it creates.

    
    

    Do you have to do it one way or the other? No. Is one more advantageous than the other? Well, the second way allows you more control of the UI, the first way is easier. Take your pick, really. I've never personally done it the second way, but I think there might be a couple of places where it might be useful.

提交回复
热议问题