title: How to use a Binding of the ViewModel instead of the DataType of a ListView?
body: <p>Let me begin with apologizing for the perhaps somewhat vague title, I'm having a hard time explaining my problem! Perhaps this is why I'm hardly getting any Google results, with this post being the closest to my problem (I think): <a href="https://stackoverflow.com/questions/1338848/how-to-bind-to-a-property-of-the-viewmodel-from-within-a-gridview">How to bind to a property of the ViewModel from within a GridView</a></p>
  
  <p>Anyways, I have a list of news articles that are being dynamically generated. The user has the option to press a "Star"-button in order to add an article to his/her favorites list. This "Star"-button should thus only be visible when the user is logged in.</p>
  
  <p>I'm trying to achieve this by setting the Visibility of the Button to a property called IsLoggedIn inside my ViewModel. However, because this is happening inside my ListView it's trying to find the property IsLoggedIn inside of Article instead of the ViewModel.</p>
  
  <p>So I guess my questions boils down to: How can I bind to a ViewModel property inside of a Databound ListView?</p>
  
  <pre><code>&lt;ListView ItemsSource="{x:Bind VM.Articles, Mode=OneWay}" ItemClick="DebuggableListView_ItemClick" IsItemClickEnabled="True" SelectionMode="None" Grid.Row="1" VerticalAlignment="Top"&gt;
      &lt;ListView.ItemTemplate&gt;
          &lt;DataTemplate x:DataType="models:Article"&gt;
              &lt;Grid Margin="0,10,10,10"&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="1*"/&gt;
                      &lt;ColumnDefinition Width="4*"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;Image Source="{Binding Image}" Margin="0,0,10,0" Grid.Column="0" VerticalAlignment="Top" ImageFailed="Image_ImageFailed"/&gt;
                  &lt;Button Visibility="{x:Bind VM.IsLoggedIn, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" FontFamily="Segoe MDL2 Assets" Content="&amp;#xE734;" FontSize="30" Background="Transparent" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom"/&gt;
                  &lt;StackPanel Grid.Column="1"&gt;
                      &lt;TextBlock TextWrapping="Wrap" FontWeight="Bold" Text="{Binding Title}"/&gt;
                      &lt;TextBlock TextWrapping="Wrap" Text="{Binding Summary}"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p><strong>Requested Article class:</strong></p>
  
  <pre><code>public sealed class Article
  {
      public int Id { get; set; }
      public int Feed { get; set; }
      public string Title { get; set; }
      public string Summary { get; set; }
      public DateTime PublishDate { get; set; }
      public string Image { get; set; }
      public string Url { get; set; }
      public string[] Related { get; set; }
      public Category[] Categories { get; set; }
      public bool IsLiked { get; set; }
  }
  </code></pre>
  
  <p>Okay, so currently I got it working by having a property which gets the singleton of my VM, however I'm sure there has to be a cleaner way to get something simple like this working. I've added a sample rar (OneDrive link: <a href="https://1drv.ms/u/s!Ar4fOTiwmGYnyWbwRY6rM0eFsL9x" rel="nofollow noreferrer">https://1drv.ms/u/s!Ar4fOTiwmGYnyWbwRY6rM0eFsL9x</a>) which has a list, a ViewModel, some dummy data and a Visibility property inside the VM. If you can get it working without my dirty method please feel free to commit as an answer.</p>