title: Displaying ObservableCollection in Listview
body: <p>I've been struggling for a while to get this to work.</p>
  
  <p>I don't think this is a duplicate, since no other post I found had this issue or helped me solve mine, but if it is a duplicate, I apologize.</p>
  
  <p>I have a UserControl that inherits from another UserControl. This child needs to display a list of items not present or needed for the other children of my base.</p>
  
  <p>C#:</p>
  
  <pre><code>public partial class EntitlementUserControl : BaseUserControl
  {
    public ObservableCollection&lt;Entitlement&gt; EntitlementCollection { get; set; } = new ObservableCollection&lt;Entitlement&gt;();
  
    public EntitlementUserControl()
    {
      InitializeComponent();
      this.DataContext = this;
      EntitlementCollection.Add(new Entitlement("Test"));
    }
  }
  </code></pre>
  
  <p>EntitlementID here should display the "Test" entered in the constructor.</p>
  
  <p>WPF:</p>
  
  <pre><code>    &lt;ListView x:Name="entitlementList" ItemsSource="{Binding EntitlementCollection}" &gt;
    &lt;ItemsControl.ItemsPanel&gt;
      &lt;ItemsPanelTemplate&gt;
        &lt;UniformGrid Columns="5" HorizontalAlignment="Stretch"/&gt;
      &lt;/ItemsPanelTemplate&gt;
    &lt;/ItemsControl.ItemsPanel&gt;
    &lt;ListView.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;TextBlock Text="{Binding Path=EntitlementID}"/&gt;
      &lt;/DataTemplate&gt;
    &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>This doesn't work for me, I found <a href="https://stackoverflow.com/questions/43604966/wpf-bind-list-to-listview">this</a> that explained I needed the DataContext, but even with it, it doesn't display my values correctly. An item shows up in the ListView, but it's empty and doesn't contain any text, picture below. The black is my styleresource because it's selected to show that one item is created.</p>
  
  <p><img src="https://i.stack.imgur.com/Z6RJH.png" alt="Picture"></p>
  
  <p>However, if I change the XAML to instead have a Gridview in the listview, it displays my data, but my goal is to format data, not show a grid.</p>
  
  <p>Working Xaml with Gridview:</p>
  
  <pre><code>&lt;ListView x:Name="entitlementList" ItemsSource="{Binding EntitlementCollection}" &gt;
    &lt;ListView.View&gt;
    &lt;GridView&gt;
      &lt;GridViewColumn Header="ID" DisplayMemberBinding="{Binding EntitlementID}"/&gt;
    &lt;/GridView&gt;
    &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bbRII.png" alt="Working GridView"></p>
  
  <p>As you can see, this shows correctly the "Test" in the ID Column. However I want to be able to show the list without any columns and be able to apply the formatting I want. Any ideas why the first way isn't working?</p>
  
  <p>Entitlement is just a small class containing the ID and a list of products.
  Entitlement:</p>
  
  <pre><code>public class Entitlement
  {
    List&lt;Product&gt; products;
  
    public List&lt;Product&gt; Products { get =&gt; products; set =&gt; products = value; }
    public string EntitlementID { get =&gt; entitlementID; set =&gt; entitlementID = value; }
  
    string entitlementID;
  
    public void AddProduct(Product product)
    {
      Products.Add(product);
    }
  
    public Entitlement(string entitlementID)
    {
      products = new List&lt;Product&gt;();
      this.entitlementID = entitlementID;
    }
  
    public override string ToString()
    {
      return EntitlementID;
    }
  }
  </code></pre>
  
  <p>Please let me know if you need more code.</p>
  
  <p>Style used for ListView (Not made by me, provided for me):</p>
  
  <pre><code>&lt;Style TargetType="{x:Type ListViewItem}"  &gt;
  &lt;Setter Property="Template"&gt;
    &lt;Setter.Value&gt;
      &lt;ControlTemplate TargetType="{x:Type ListViewItem}"&gt;
        &lt;Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="2"
                SnapsToDevicePixels="true"&gt;
          &lt;Border x:Name="InnerBorder" CornerRadius="1" BorderThickness="1"&gt;
            &lt;Grid&gt;
              &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition MinHeight="18"/&gt;
                &lt;RowDefinition/&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;Rectangle x:Name="UpperHighlight" Visibility="Collapsed" Fill="{StaticResource UpperReflection_Normal_BackgroundBrush}"/&gt;
              &lt;GridViewRowPresenter Grid.RowSpan="2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt;
            &lt;/Grid&gt;
          &lt;/Border&gt;
        &lt;/Border&gt;
        &lt;ControlTemplate.Triggers&gt;
          &lt;Trigger Property="IsMouseOver" Value="true"&gt;
            &lt;Setter Property="Background" Value="{StaticResource FlatButton_MouseOver_BackgroundBrush}"/&gt;
            &lt;Setter Property="BorderBrush" Value="{StaticResource FlatButton_MouseOver_BorderBrush}"/&gt;
            &lt;Setter Property="BorderBrush" TargetName="InnerBorder" Value="{StaticResource FlatButton_MouseOver_InnerBorderBrush}" /&gt;
            &lt;Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible"/&gt;
          &lt;/Trigger&gt;
          &lt;!--&lt;Trigger Property="Helpers:ItemDragState.IsUnderDragCursor" Value="True"&gt;
            &lt;Setter Property="Background" Value="{StaticResource ListViewItem_Hover_BackgroundBrush}"/&gt;
            &lt;Setter Property="BorderBrush" Value="{StaticResource ListViewItem_Hover_BorderBrush}"/&gt;
            &lt;Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible"/&gt;
          &lt;/Trigger&gt;--&gt;
          &lt;Trigger Property="IsSelected" Value="true"&gt;
            &lt;Setter Property="Background" Value="{StaticResource ListItemSelectedFill_BackgroundBrush}"/&gt;
            &lt;Setter Property="BorderBrush" Value="{StaticResource ListItemSelectedFill_BorderBrush}"/&gt;
                          &lt;Setter Property="Foreground" Value="White" /&gt;
                          &lt;Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource ListViewItem_Selected_InnerBorderBrush}"/&gt;
            &lt;Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible"/&gt;
            &lt;Setter TargetName="UpperHighlight" Property="Fill" Value="#40FFFFFF"/&gt;
          &lt;/Trigger&gt;
          &lt;MultiTrigger&gt;
            &lt;MultiTrigger.Conditions&gt;
              &lt;Condition Property="IsSelected" Value="true"/&gt;
              &lt;Condition Property="Selector.IsSelectionActive" Value="false"/&gt;
            &lt;/MultiTrigger.Conditions&gt;
            &lt;Setter Property="Background" Value="{StaticResource ListItemSelectedInactiveFill_BackgroundBrush}"/&gt;
            &lt;Setter Property="BorderBrush" Value="{StaticResource ListItemSelectedInactiveFill_BorderBrush}"/&gt;
          &lt;/MultiTrigger&gt;
          &lt;MultiTrigger&gt;
            &lt;MultiTrigger.Conditions&gt;
              &lt;Condition Property="IsSelected" Value="true"/&gt;
              &lt;Condition Property="IsMouseOver" Value="true"/&gt;
            &lt;/MultiTrigger.Conditions&gt;
            &lt;Setter Property="Background" Value="{StaticResource ListItemSelectedHoverFill_BackgroundBrush}"/&gt;
            &lt;Setter Property="BorderBrush" Value="{StaticResource ListItemSelectedHoverFill_BorderBrush}"/&gt;
          &lt;/MultiTrigger&gt;
          &lt;Trigger Property="IsEnabled" Value="false"&gt;
            &lt;Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt;
          &lt;/Trigger&gt;
        &lt;/ControlTemplate.Triggers&gt;
      &lt;/ControlTemplate&gt;
    &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  </code></pre>
  
  <p></p>