{"id":410,"date":"2013-09-25T05:27:00","date_gmt":"2013-09-25T05:27:00","guid":{"rendered":"http:\/\/www.benbarefield.com\/blog\/?p=410"},"modified":"2013-10-06T00:05:09","modified_gmt":"2013-10-06T00:05:09","slug":"layout-controls-itemscontrol","status":"publish","type":"post","link":"https:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-itemscontrol\/","title":{"rendered":"Layout Controls: ItemsControl"},"content":{"rendered":"<p>The ItemsControl component is used to dynamically generate other UI controls. It does not place the elements on its own, it only creates them and adds them as children. The ItemsControl prefab uses a LayoutStackingPanel to manage the placement of the items it creates. ItemsControl has two important properties:\u00a0<strong>Items<\/strong> and\u00a0<strong>Item Template<\/strong>.<\/p>\n<ul>\n<li><strong>Item Template<\/strong>: this can be set to a prefab in the inspector. When the ItemsControl creates its children, it will create an instance of this prefab.<\/li>\n<li><strong>Items<\/strong>: cannot be edited in the inspector, but can be used as a target in <a href=\"http:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-bindable-and-data-bind\/\">Data Binding<\/a>. The ItemsControl will create one instance of the <strong>ItemTemplate<\/strong> for each item in this IEnumerable. If the created instance has a <a href=\"http:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-bindable-and-data-bind\/\">Bindable<\/a> component, the item that the instance was created for will be set as the Data Context.<\/li>\n<\/ul>\n<p><strong>ObservableCollection&lt;T&gt;<\/strong><\/p>\n<p>ObservableCollection implements IEnumberable&lt;T&gt;, IList&lt;T&gt;, and INotifyPropertyChanged with an added\u00a0<strong>CollectionChanged<\/strong> event. When an element is added to, removed from, or swapped in (via List[index] = ) the backing List, CollectionChanged is fired. When an item is added or removed from the backing list PropertyChanged is fired for the Count property.<\/p>\n<p>If the\u00a0<strong>Items<\/strong> property of an ItemsControl is bound to an ObservableCollection, the ItemsControl will attach to the CollectionChanged event and dynamically update the children (create or destroy) when items are added to or removed from the backing ObservableCollection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ItemsControl component is used to dynamically generate other UI controls. It does not place the elements on its own, it only creates them and adds them as children. The ItemsControl prefab uses a LayoutStackingPanel to manage the placement of &hellip; <a href=\"https:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-itemscontrol\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-410","post","type-post","status-publish","format-standard","hentry","category-layout-controls"],"_links":{"self":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/comments?post=410"}],"version-history":[{"count":5,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/410\/revisions"}],"predecessor-version":[{"id":468,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/410\/revisions\/468"}],"wp:attachment":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/media?parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/categories?post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/tags?post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}