title: How to remove all selected items from an ObservableCollection
body: <p>I'm trying to remove all the selected items from the ObservableCollection when a button in a different XAML is clicked, I am unsure on how I can implement it in my system. I'm using this example to guide me - <a href="https://stackoverflow.com/questions/5118513/removeall-for-observablecollections">RemoveAll for ObservableCollections?</a></p>
  
  <p>Below is my code:</p>
  
  <p><strong>Basket.xaml which contains the observablecollection</strong></p>
  
  <pre><code>private static ObservableCollection&lt;Menu.PassedData&gt; passedData = new ObservableCollection&lt;Menu.PassedData&gt;();
      public ObservableCollection&lt;Menu.PassedData&gt; PassedData
      {
  
          get { return passedData; }
          //get{ passedData = value; }
  
      bool IsSelected = true;
      }
  </code></pre>
  
  <p><strong>Listview in Basket</strong></p>
  
  <pre><code> &lt;ListBox x:Name="listBox" HorizontalAlignment="Left" Height="270" Margin="10,170,0,0" VerticalAlignment="Top" Width="125" IsSynchronizedWithCurrentItem="False" SelectionChanged="listBox_SelectionChanged"&gt;
          &lt;ListView Name ="myListView" ItemsSource="{Binding PassedData}" HorizontalAlignment="Left" VerticalAlignment="Center"&gt;
              &lt;ListView.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Grid&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="auto"/&gt;
                              &lt;ColumnDefinition Width="auto"/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="auto"/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;TextBox Grid.Column="0" Text="{Binding Name}" IsReadOnly="True" FontSize="15" /&gt;
                          &lt;TextBox x:Name="quanttextBox" HorizontalAlignment="Left" Height="25" Margin="155,175,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="95" TextChanged="quanttextBox_TextChanged"/&gt;
                          &lt;!--&lt;TextBox Grid.Column="1" Text="{Binding Value}" /&gt; !--&gt;
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListView.ItemTemplate&gt;
          &lt;/ListView&gt;
  
      &lt;/ListBox&gt;
  </code></pre>
  
  <p><strong>Confirm.xaml is the page which cotains the button to remove all the items</strong></p>
  
  <pre><code>  public static class ObservableCollectionExtensions
  {
      public static void RemoveAll&lt;T&gt;(this ObservableCollection&lt;T&gt; collection,
                                                         Func&lt;T, bool&gt; condition)
      {
          for (int i = collection.Count - 1; i &gt;= 0; i--)
          {
              if (condition(collection[i]))
              {
                  collection.RemoveAt(i);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>The button itself</strong></p>
  
  <pre><code>       private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
      {
          Menu.PassedData.RemoveAll(data =&gt; data.IsSelected == true);
  
          Frame.Navigate(typeof(MainPage));
  
      }
  </code></pre>
  
  <p><strong>Menu.PassedData</strong></p>
  
  <pre><code>       public event SelectionChangedEventHandler SelectionChanged;
      public class PassedData
      {
          public string Name { get; set; }
          public double Value { get; set;}
  
          bool IsSelected = true;
  
          internal static void RemoveAll(Func&lt;object, bool&gt; p)
          {
              throw new NotImplementedException();
          }
      }
  </code></pre>
  
  <p><strong>Error</strong>
  <a href="https://i.stack.imgur.com/nzFnh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nzFnh.png" alt="enter image description here"></a></p>