title: how to refer to item in an enumeration within a ListView
body: <p>I have a class MRU which contains an ObservableCollection of type string. I would like to display the items within the collection on a PopupPage in a ListView.</p>
  <pre><code>[DefaultBindingProperty(&quot;Items&quot;)] 
  public class MRU&lt;T&gt; :INotifyPropertyChanged
  {
      public ObservableCollection&lt;T&gt; Items { get; } = new ObservableCollection&lt;T&gt;();
  
      // This is the maximum number of items that will be saved to persistent storage, 
      // in use the list can grow beyond this number
      private int _MaxItems = 5;
      public int MaxItems
      {
          get { return _MaxItems; }
          set { 
              _MaxItems = value;
              TrimItems();
              OnPropertyChanged(); 
          }
      }
      public void Add(T t) {
          int idx = Items.IndexOf(t);
          if (idx &gt; 0)
          {
              Items.Move(idx, 0);
          }
          else if (idx == -1)
          {
              Items.Insert(0, t);
          }
      }
      
      public T Pop(int i)
      {
          if (i &gt; 0 &amp;&amp; i &lt; Items.Count)
          {
              Items.Move(i, 0);
          }
          return Items[0];
      }
  
      private void TrimItems()
      {
          while (Items.Count &gt; _MaxItems)
          {
              Items.RemoveAt(Items.Count - 1);
          }
  
      }
      public void Save()
      {
          App.Current.Properties[&quot;MRU&quot;] = SaveToJSON();
          App.Current.SavePropertiesAsync();
      }
  
      public string SaveToJSON()
      {
          TrimItems();
          string jsonString = JsonSerializer.Serialize(Items);
          return jsonString;
      }
      public int LoadFromJSON(string jsonString)
      {
          Items.Clear();
          ObservableCollection&lt;T&gt; restore = JsonSerializer.Deserialize&lt;ObservableCollection&lt;T&gt;&gt;(jsonString);
          foreach (var t in restore)
          {
              if (Items.Count == _MaxItems) break;
              Items.Add(t);
          }
          return Items.Count;
      }
      protected void OnPropertyChanged([CallerMemberName] string name = null)
      {
          PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
      }
      public event PropertyChangedEventHandler PropertyChanged;
  
  }
  </code></pre>
  <p>I can display it in my page using the following XAML</p>
  <pre><code>   &lt;StackLayout 
          VerticalOptions=&quot;Center&quot; 
          HorizontalOptions=&quot;Center&quot; 
          Padding=&quot;0,20&quot;&gt;
          &lt;Frame BackgroundColor=&quot;White&quot; CornerRadius=&quot;15&quot;&gt;
              &lt;StackLayout&gt;
                  &lt;Label Text=&quot;Most Recently Used&quot; FontSize=&quot;Large&quot; BackgroundColor=&quot;LightBlue&quot; HorizontalOptions=&quot;CenterAndExpand&quot; Padding=&quot;20,4&quot;/&gt;
                  &lt;StackLayout &gt;
                      &lt;ListView ItemsSource=&quot;{Binding Items}&quot; SelectionMode=&quot;Single&quot;&gt; 
                          &lt;!--&lt;ListView.ItemTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;StackLayout Orientation=&quot;Vertical&quot;&gt;
                                      &lt;Label Text=&quot;{Binding XXXXXX}&quot;  VerticalOptions=&quot;Center&quot; HorizontalTextAlignment=&quot;End&quot;  FontSize=&quot;Medium&quot;/&gt;
                                  &lt;/StackLayout&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/ListView.ItemTemplate&gt; --&gt;
                      &lt;/ListView&gt;
                  &lt;/StackLayout&gt;
               &lt;/StackLayout&gt;
          &lt;/Frame&gt;
      &lt;/StackLayout&gt;
  </code></pre>
  <p>Note the commented out ListView.ItemTemplate section. I would like to display the items within an ItemTemplate so that I can add buttons for each object, however I don't know how to declare it . What should  XXXXX be? I've tried a zillion unlikely things</p>