ItemsControl, ItemsPanel and ItemsPresenter (Silverlight, XAML)

后端 未结 2 528
迷失自我
迷失自我 2021-02-05 07:58

I\'m utterly confused by these 3 terms, when to use which? What\'s the relationship and they are children of which controls?

Is it correct to say this is the tree:

2条回答
  •  半阙折子戏
    2021-02-05 08:03

    ItemsControl is conceptually a control that houses items. Try to simply think of this control as a holder for zero or more objects.

    ItemsPresenter is a bit tougher to explain, but this is part of the ItemsControl template that will define where the items are placed within it. Your ItemsControl's template can be anything you like, say a Grid with some pretty pictures around it, inside this template, you would place the ItemsPresenter where ever you want your items to be, say right in the middle of your grid. (this example is taken from msdn and simplified for ease of reading)

    
    

    The ItemsPanel is the panel (or container) that controls the layout of the items in your ItemsControl. So if you want your items that you have added to your ItemsControl to display in a horizotal way, then yor items panel could simply be a StackPanel with its Orientation property set to Horizontal.

    This all make sense?

提交回复
热议问题