title: How to have the click event of a ListView item turn on and off the checkbox in the item template for the listview
body: <p>I have UWP app with a XAML listview in a user control as seen below.</p>
  
  <pre><code>&lt;ListView x:Name="lvDevices"
            Margin="12,8,0,0"
            Grid.Row="4"
            HorizontalContentAlignment="Stretch"
            ItemTemplate="{StaticResource DeviceTemplate}"
            Width="Auto"
            ItemsSource="{Binding Devices}"
            IsItemClickEnabled="True"
            ItemClick="lvDevices_ItemClick"
            d:DataContext="{d:DesignData /SampleData/DevicesVMSampleData.xaml}" &gt;
      &lt;ListView.ItemContainerStyle&gt;
          &lt;Style TargetType="ListViewItem"&gt;
              &lt;Setter Property="HorizontalAlignment" Value="Stretch"/&gt;
              &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt;
          &lt;/Style&gt;
      &lt;/ListView.ItemContainerStyle&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>The listview's item template is as follows.  You can see the item template has a check box and it is bound to my view model using two way binding.</p>
  
  <pre><code>&lt;DataTemplate x:Key="DeviceTemplate"&gt;
          &lt;Grid Margin="0" HorizontalAlignment="Stretch" &gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;ColumnDefinition Width="*"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;CheckBox x:Name="chkSelected" IsChecked="{Binding Selected, Mode=TwoWay}" MinWidth="32" Grid.Column="0" Checked="chkSelected_Changed" Unchecked="chkSelected_Changed" /&gt;
              &lt;StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="10,0,0,0"&gt;
                  &lt;TextBlock Text="{Binding DeviceName}" Style="{StaticResource TitleTextBlockStyle}" Tag="{Binding ID}" TextWrapping="Wrap" MaxWidth="500"/&gt;
                  &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBlock Text="User:" Margin="0,0,10,0" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" /&gt;
                      &lt;TextBlock Text="{Binding User}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/StackPanel&gt;
              &lt;Button x:Name="btnInfo" Grid.Column="2" Background="Transparent" HorizontalAlignment="Right"&gt;
                  &lt;Image x:Name="imgInfo" HorizontalAlignment="Right" VerticalAlignment="Center" Source="/Assets/InfoIcon-100.png" Height="50" Width="50" /&gt;
              &lt;/Button&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>The listview's datacontext is set to my view model.  </p>
  
  <pre><code>ucDeviceInfo.DataContext = iobj_DevicesViewModel;
  </code></pre>
  
  <p>So what I want is when the user clicks on anitem in the listview, the checkbox for that item updated with a check mark or have its check mark removed.  I figured the best way to do that would be to set the 'Selected' property in the ViewModel to true or false when the user clicks on the row then notify the view that the property has changed.  (The list of items is an observable collection.).</p>
  
  <p>I try to accomplish this in the following manner:  </p>
  
  <p>In the UserControl - when the user clicks on a row I call a method back in the base page using this code:</p>
  
  <pre><code>private void lvDevices_ItemClick(object sender, ItemClickEventArgs e)
      {
          StartPage lobj_ParentForm;         
  
          lobj_ParentForm = ((StartPage)((Frame)Window.Current.Content).Content);
          lobj_ParentForm.SendNotifyPropertyChanged( ((Device)e.ClickedItem).ID);
      }
  </code></pre>
  
  <p>In the base page I call a method in my ViewModel using this code:</p>
  
  <pre><code>public void SendNotifyPropertyChanged(int pi_DeviceID)
      {
          iobj_DevicesViewModel.DeviceSelectedInListView(pi_DeviceID);
      }
  </code></pre>
  
  <p>Then in the view model I update the selected property for the device and call the notify property changed function using this code:</p>
  
  <pre><code>public void DeviceSelectedInListView(int pi_DeviceID)
      {
          Device lobj_SelectedDevice;
  
          lobj_SelectedDevice = (from lobj_Device in Devices
                         where lobj_Device.ID == pi_DeviceID
                         select lobj_Device).ToList&lt;Device&gt;()[0];
  
  
          lobj_SelectedDevice.Selected = !lobj_SelectedDevice.Selected;
          NotifyPropertyChanged("Devices");
          SelectionsChanged();
      }
  
      public void SelectionsChanged()
      {
          NotifyPropertyChanged("SelectedDeviceCount");
      }
  </code></pre>
  
  <p>The challenge is that when I do this and call the notify property changed method, the checkbox of the item in the listview I just clicked on is not updated.  Any idea how I can get the checkbox to update correctly when a user clicks on a row in the listview?</p>
  
  <p>Link to sample project that illustrates this issue is
  <a href="https://github.com/gceaser/ListViewWithCheckBox" rel="nofollow">Example Code</a></p>