title: Multiple selection in WPF MVVM ListBox
body: <p>I have a ListBox containing filenames. Now I need to get array of selected items from this ListBox. I found a few answers here, but none of them worked for me. I'am using Caliburn Micro framework.</p>
  
  <p>Here is my View:</p>
  
  <pre><code>&lt;Window x:Class="ProgramsAndUpdatesDesktop.Views.DeleteHistoryView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:ProgramsAndUpdatesDesktop.Views"
      mc:Ignorable="d"
      ResizeMode="CanResizeWithGrip"
      MaxWidth="300"
      MinWidth="300"
      MinHeight="500"
      Title="DeleteHistoryView" Height="500" Width="300"&gt;
  &lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="*" /&gt;
          &lt;RowDefinition Height="30" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;StackPanel Grid.Column="0" Grid.Row="0"&gt;
          &lt;ListBox x:Name="DeleteHistoryListBox" SelectedItem="{Binding Path=DeleteHistorySelectedItem}" 
                   ItemsSource="{Binding DeleteHistoryListBox, NotifyOnSourceUpdated=True}" 
               SelectionMode="Multiple"&gt;
          &lt;/ListBox&gt;
      &lt;/StackPanel&gt;
      &lt;StackPanel Grid.Column="0" Grid.Row="1"&gt;
          &lt;Button x:Name="DeleteHistoryButtonAction"&gt;Delete&lt;/Button&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is my ViewModel:</p>
  
  <pre><code>class DeleteHistoryViewModel : Screen
  {
      string historyFolderPath = Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["HistoryFolderPath"]);
  
      private ObservableCollection&lt;string&gt; deleteHistoryListBox = new ObservableCollection&lt;string&gt;();
      public ObservableCollection&lt;string&gt; DeleteHistoryListBox
      {
          get { return deleteHistoryListBox; }
          set { deleteHistoryListBox = value; NotifyOfPropertyChange(() =&gt; DeleteHistoryListBox); }
      }
  
      private List&lt;string&gt; deleteHistorySelectedItem = new List&lt;string&gt;();
      public List&lt;string&gt; DeleteHistorySelectedItem
      {
          get { return deleteHistorySelectedItem; }
          set { deleteHistorySelectedItem = value; }
      }
  
      public DeleteHistoryViewModel()
      {
          base.DisplayName = "Delete History";
      }
  
      protected override void OnInitialize()
      {
          FillListBox();
      }
  
      private void FillListBox()
      {
          string[] directory = Directory.GetFiles($"{historyFolderPath}\\", "*.json");
  
          foreach (var item in directory)
          {
              string fileName = System.IO.Path.GetFileName(item).ToString();
              if (!DeleteHistoryListBox.Contains(fileName))
              {
                  DeleteHistoryListBox.Add(fileName);
              }
          }
      }
  
      #region ACTIONS REGION
  
      // DELETE HISTORY ACTION
      public void DeleteHistoryButtonAction()
      {
          foreach (var item in DeleteHistorySelectedItem)
          {
              MessageBox.Show(item);
          }
      }
  
      #endregion
  
  }
  </code></pre>