<?xml version="1.0" encoding="utf-8" ?>
<Mcml xmlns="http://schemas.microsoft.com/2008/mcml" 
      xmlns:btn="<!--Path to Button.mcml-->"
      xmlns:code="<!--Path to the assembly containing the ListSelection class-->"
  <!--simple list of buttons, reports the selected item and its index-->
  <UI Name="List">

      <!--passed to list items, holds the selected item and its index-->
      <code:ListSelection Name="Selection" />
      <!--data source to create the list items from-->
      <coll:IList Name="Model" IList="$Required" />
      <!--command invoked on the selected item when clicked-->
      <ICommand Name="Command" ICommand="$Required" />

      <!--selected item-->
      <cor:Object Name="SelectedItem" Object="null" />
      <!--index of the selected item-->
      <cor:Int32 Name="SelectedIndex" Int32="-1" />


      <!--bind selection to properties-->
      <Binding Source="[Selection.Index]" Target="[SelectedIndex]" />      
      <Binding Source="[Selection.Item]" Target="[SelectedItem]" />
      <!--repeats the content for each item in the data source-->
      <Repeater Source="[Model]">
          <GridLayout AllowWrap="true" Orientation="Vertical" />
          <!--list item requires details about the current item and must be able to update the selection-->
          <me:ListItem Index="[RepeatedItemIndex]" Item="[RepeatedItem]" SelectionHolder="[Selection]">
              <!--invokes the main command while providing a unique description for each item-->
              <InvokeCommand Description="[RepeatedItem.ToString]" Target="[Command.Invoke]" />

  <!--UI element for each item in a list, extends the Button-->
  <UI Name="ListItem" BaseUI="btn:Button">

      <!--reference to the list's selection-->
      <code:ListSelection Name="SelectionHolder" ListSelection="$Required" />
      <!--data source item (and its index) that was used to create the list item-->
      <Index Name="Index" Index="$Required" />
      <cor:Object Name="Item" Object="$Required" />

      <!--updates the list's selection when the list item receives keyboard/mouse focus-->
      <Condition Source="[Input.KeyFocus]" SourceValue="true">
          <Set Target="[SelectionHolder.Index]" Value="[Index.Value]" />
          <Set Target="[SelectionHolder.Item]" Value="[Item]" />