title: Update Listview with view model with button click
body: <p>I want to be able to update the listview when a user clicks on a listview item (row) and clicks a button. Here is my code:</p>
  
  <p>XAML</p>
  
  <pre><code>&lt;Window x:Class="CS3000Config2.Dialogs.Clone"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:CS3000Config2"
  Title="Clone Scanner Configuration" Height="768" Width="1024" FontSize="16" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" Loaded="Window_Loaded"&gt;
  &lt;Window.Resources&gt;
      &lt;local:ScannerViewModel x:Key="ViewModel" /&gt;
  &lt;/Window.Resources&gt;
  &lt;Window.Background&gt;
      &lt;LinearGradientBrush EndPoint=".5,1" StartPoint=".5,0"&gt;
          &lt;GradientStop Color="#b8e1fc" Offset="0" /&gt;
          &lt;GradientStop Color="#a9d2f3" Offset="0.10" /&gt;
          &lt;GradientStop Color="#90bae4" Offset="0.25" /&gt;
          &lt;GradientStop Color="#90bcea" Offset="0.37" /&gt;
          &lt;GradientStop Color="#90bff0" Offset=".50" /&gt;
          &lt;GradientStop Color="#6ba8e5" Offset=".51" /&gt;
          &lt;GradientStop Color="#a2daf5" Offset=".83" /&gt;
          &lt;GradientStop Color="#bdf3fd" Offset="1" /&gt;
      &lt;/LinearGradientBrush&gt;
  &lt;/Window.Background&gt;
  
  &lt;DockPanel&gt;
      &lt;Grid&gt;
          &lt;DockPanel Height="650" Margin="50,40,50,0" Width="800" VerticalAlignment="Top" Background="White"&gt;
              &lt;Grid&gt;
                  &lt;ToolBar Height="46" Margin="0,6,-11,0" Name="toolBar1" VerticalAlignment="Top" ToolBarTray.IsLocked="True" BorderBrush="Black" BorderThickness=".5" Loaded="toolBar1_Loaded"&gt;
                      &lt;Button ToolBar.OverflowMode="AsNeeded" Click="Button_Click" Name="btnLoadToSelected"&gt;
                          &lt;StackPanel  Orientation="Horizontal" VerticalAlignment="Center" &gt;
                              &lt;StackPanel.Resources&gt;
                                  &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                      &lt;Setter Property="Margin" Value="10,0,0,0"/&gt;
                                  &lt;/Style&gt;
                              &lt;/StackPanel.Resources&gt;
                              &lt;Image Source="/CS3000Config2;component/Resources/dsave.png" /&gt;
                              &lt;TextBlock VerticalAlignment="Center" FontSize="16" Margin="5,0,0,0"&gt;Load To Selected Scanners&lt;/TextBlock&gt;
                          &lt;/StackPanel&gt;
                      &lt;/Button&gt;
                      &lt;Separator /&gt;
                      &lt;Button ToolBar.OverflowMode="Never" Click="Button_Click_2" Name="btnLoadToAll"&gt;
                          &lt;StackPanel  Orientation="Horizontal" VerticalAlignment="Center" &gt;
                              &lt;StackPanel.Resources&gt;
                                  &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                      &lt;Setter Property="Margin" Value="10,0,0,0"/&gt;
                                  &lt;/Style&gt;
                              &lt;/StackPanel.Resources&gt;
                              &lt;Image Source="/CS3000Config2;component/Resources/document-save-all2.png" /&gt;
                              &lt;TextBlock VerticalAlignment="Center" FontSize="16" Margin="5,0,0,0"&gt; Load To All Scanners&lt;/TextBlock&gt;
                          &lt;/StackPanel&gt;
                      &lt;/Button&gt;
                      &lt;Separator /&gt;
                      &lt;Button ToolBar.OverflowMode="Never" Click="Button_Click_1"&gt;
                          &lt;StackPanel  Orientation="Horizontal" VerticalAlignment="Center" &gt;
                              &lt;StackPanel.Resources&gt;
                                  &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                      &lt;Setter Property="Margin" Value="10,0,0,0"/&gt;
                                  &lt;/Style&gt;
                              &lt;/StackPanel.Resources&gt;
                              &lt;Image Source="/CS3000Config2;component/Resources/refresh.gif" /&gt;
                              &lt;TextBlock VerticalAlignment="Center" FontSize="16" Margin="5,0,0,0"&gt; Refresh Scanner List&lt;/TextBlock&gt;
                          &lt;/StackPanel&gt;
                      &lt;/Button&gt;
                      &lt;Separator /&gt;
                  &lt;/ToolBar&gt;
                  &lt;ScrollViewer Margin="6.5,58,6,6" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" &gt;
                      &lt;Grid DataContext="{Binding Source={StaticResource ViewModel}}" Name="grid1"&gt;
  
  
                          &lt;ListView  Margin="0,5" Name="listView1" SelectionMode="Multiple" ItemsSource="{Binding Scanners}"&gt;
                              &lt;ListView.View&gt;
                                  &lt;GridView&gt;
                                      &lt;GridViewColumn Header="" Width="100"&gt;
                                          &lt;GridViewColumn.CellTemplate&gt;
                                              &lt;DataTemplate&gt;
                                                  &lt;Image Height="50" Source="/CS3000Config2;component/Resources/cs3000-small.png" /&gt;
                                              &lt;/DataTemplate&gt;
                                          &lt;/GridViewColumn.CellTemplate&gt;
                                      &lt;/GridViewColumn&gt;
                                      &lt;GridViewColumn Header="Drive" Width="50" DisplayMemberBinding="{Binding Drive}" /&gt;
                                      &lt;GridViewColumn Header="Model" Width="100" DisplayMemberBinding="{Binding Model}" /&gt;
                                      &lt;GridViewColumn Header="Serial" Width="200" DisplayMemberBinding="{Binding Serial}" /&gt;
                                      &lt;GridViewColumn Header="" Width="325" &gt;
                                          &lt;GridViewColumn.CellTemplate&gt;
                                              &lt;DataTemplate&gt;
                                                  &lt;ProgressBar Name="prog1" Visibility="{Binding isVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Maximum="{Binding maxProgress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Value="{Binding progress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="20" Width="200" /&gt;
                                              &lt;/DataTemplate&gt;
                                          &lt;/GridViewColumn.CellTemplate&gt;
                                      &lt;/GridViewColumn&gt;
                                  &lt;/GridView&gt;
                              &lt;/ListView.View&gt;
                          &lt;/ListView&gt;
  
                      &lt;/Grid&gt;
                  &lt;/ScrollViewer&gt;
              &lt;/Grid&gt;
          &lt;/DockPanel&gt;
  
      &lt;/Grid&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p>View Model (ScannerViewModel.cs)</p>
  
  <pre><code>public class ScannerViewModel : INotifyPropertyChanged
  {
  
      private String[] scanners;
  
      ObservableCollection&lt;Scanner&gt; items = new ObservableCollection&lt;Scanner&gt;();
      private ArrayList driveList = new ArrayList();
      public ScannerViewModel()
      {
          GetDrives();
          scanners = (String[])driveList.ToArray(typeof(String));
  
          if (scanners.Length &lt;= 0)
          {
              return;
          }
          else
          {
              foreach (String scnr in scanners)
              {
                  Config c = new Config();
                  c.LoadSysInfo(scnr + "\\Parameters\\SYSINFO.TXT");
  
                  ProgressBar progBar = new ProgressBar();
                  progBar.Height = 20;
                  progBar.Width = 150;
  
                  items.Add(new Scanner() { Drive = scnr, Model = c.Model, Serial = c.Serial, maxProgress = 10000, progress = 0, isVisible= Visibility.Hidden });
              }
          }
      }
      private void GetDrives()
      {
          driveList.Clear();
          foreach (DriveInfo info in DriveInfo.GetDrives())
          {
              if (info.DriveType == DriveType.Removable)
              {
  
                  if (Directory.Exists(info.RootDirectory.ToString() + "Parameters"))
                  {
  
                      driveList.Add(info.RootDirectory.ToString());
                  }
              }
          }
      }
  
      public ObservableCollection&lt;Scanner&gt; Scanners
      {
  
          get
          {
              return items;
          }
          set
          {
              items = value;
              RaisePropertyChanged("Scanners");
          }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      private void RaisePropertyChanged(string propertyName)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null)
          {
              handler(this, new PropertyChangedEventArgs(propertyName));
          }
      }
    }
  }
  </code></pre>
  
  <p>Model class (Scanner.cs)</p>
  
  <pre><code>public class Scanner
  {
      public String Model { get; set; }
      public String Serial { get; set; }
      public Visibility isVisible { get; set; }
      public String Drive { get; set; }
      public Int32 progress { get; set; }
      public Int32 maxProgress { get; set; }
   }
  }
  </code></pre>
  
  <p>Can someone tell me how to update one of the listview rows and make the progress bar visible if a user clicks on a row in the list view and clicks the Load To Scanner button? Sample button click code would be appreciated.</p>