Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

ItemsControl

Mark Smith edited this page Apr 10, 2018 · 4 revisions

ItemsControl

The ItemsControl control is a simple, bindable template creator which will instantiate a set of Label elements or DataTemplate driven elements from a bound list. Similar to a ListView, but the produced content is not scrollable, nor does it provide any interactivity outside the generate content.

Properties

  • PlaceholderText : a string which is displayed when there is no data to render.
  • ItemsSource : the collection of data to render. This can be any IEnumerable type.
  • ItemStyle : the Style applied to any generated Label elements, including the placeholder text. If not supplied, the default Style for Label is used. This can be used to customize the generated labels.
  • ItemTemplate : the DataTemplate or DataTemplateSelector used to create the visualization for each item in the ItemsSource collection. If not supplied, simple Label elements are generated and ToString is executed on each object to provide the text.

Example

<Page xmlns:xamucontrols="clr-namespace:XamarinUniversity.Controls;assembly=XamU.Infrastructure" ..>
...
<xamucontrols:ItemsControl 
   ItemsSource="{Binding Entries}" 
   ItemStyle="{DynamicResource LabelEntryStyle}" 
   PlaceholderText="{Binding Title, StringFormat='No {0} Entered'}">

   <!-- System inflates one of these for every item in Entries collection -->
   <xamucontrols:ItemsControl.ItemTemplate>
      <DataTemplate>
         <StackLayout>
            <Label Text="{Binding Details}" />
               <!-- Other data bound elements here -->
               ...
         </StackLayout>
      </DataTemplate>
   </xamucontrols:ItemsControl.ItemTemplate>
</xamucontrols:ItemsControl>