title: Filtering ListBox.ItemsSource with CheckBoxes
body: <p>I'm pretty new to programming for Windows Phone and I'm having trouble editing data in ListBox.<br>
  I'm loading data from my XML file into a list, and displaying them in ListBox.<br>
  Each entry in my XML has a type attached to it. I want to make it so I can remove/add entries with certain types, by checking/unchecking certain CheckBoxes.</p>
  
  <p>I found something like this:<br>
  <a href="https://stackoverflow.com/questions/2611667/how-to-remove-all-listbox-items">How to remove all ListBox items?</a></p>
  
  <p>But it doesn't exactly suit my needs since I want only to delete part of ListBox items, and then possibly get it back by simply checking the checkbox again.<br>
  Also I don't want to add every entry manually since I already bound listbox with a list containing my XML entries.</p>
  
  <p>I upload my XML like so:</p>
  
  <p><code>Activity.cs</code>:</p>
  
  <pre><code>namespace ReadXMLfromFile
  {
     public class Activity
     {
        public string Type { get; private set; }
        public string Description { get; private set; }
  
        public Activity(string type, string description)
        {
             Type = type;
             Description = description;
        }
  
        public static List&lt;Activity&gt; LoadActivities(XDocument doc)
        {
          return doc .Root
                     .Elements("Activity")
                     .Select(el =&gt; new Activity((string)el.Attribute("Type"),
                                              el.Value))
                     .ToList();
        }
  
        public static List&lt;Activity&gt; LoadActivities()
        {
          using (var store = IsolatedStorageFile.GetUserStoreForApplication())
          {
              if (store.FileExists("Activities.xml"))
              {
                   using (var stream = store.OpenFile("Activities.xml",
                                                      FileMode.Open))
                   {
                       return LoadActivities(XDocument.Load(stream));
                   }
              }
          }
          // No user file... load the default activities
          return LoadActivities(XDocument.Load("Assets/Activities.xml"));
  
        }
     }
  }
  </code></pre>
  
  <p>Here is my code for my page:</p>
  
  <pre><code>namespace ActivityManager
  {
      public partial class PivotPage1 : PhoneApplicationPage
      {
          private List&lt;Activity&gt; activities;
  
          public void ActivityDisplay()
          {
              activities = Activity.LoadActivities();
              listBox1.ItemsSource = activities;
          }
  
          public PivotPage1()
          {
              InitializeComponent();
              ActivityDisplay();
          }
  
          private void CookingCheck_Checked(object sender, RoutedEventArgs e)
          {
          }
  
          private void ArtCheck_Checked(object sender, RoutedEventArgs e)
          {
          }
  
          private void LanguageCheck_Checked(object sender, RoutedEventArgs e)
          {
          }
  
          private void ScienceCheck_Checked(object sender, RoutedEventArgs e)
          {
          }
  
          private void SportCheck_Checked(object sender, RoutedEventArgs e)
          {
          }
  </code></pre>
  
  <p>And xaml for ListBox:</p>
  
  <pre><code>&lt;ListBox Height="347" HorizontalAlignment="Left" Margin="27,243,0,0" 
           Name="listBox1" VerticalAlignment="Top" Width="410" 
           SelectionChanged="listBox1_SelectionChanged" AllowDrop="False" 
           ItemsSource="{Binding activities}"&gt;
       &lt;ListBox.ItemTemplate&gt;
           &lt;DataTemplate&gt;
                &lt;StackPanel Margin="10"&gt;
                     &lt;TextBlock Text="{Binding Activity}"/&gt;
                &lt;/StackPanel&gt;
           &lt;/DataTemplate&gt;
       &lt;/ListBox.ItemTemplate&gt;
   &lt;/ListBox&gt;
  </code></pre>
  
  <p>Also here is my XML file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Activities&gt;
      &lt;Activity Type="Cooking"&gt;
        Cook some Mexican food
      &lt;/Activity&gt;
      &lt;Activity Type="Art"&gt;
        Draw a picture
      &lt;/Activity&gt;
      &lt;Activity Type="Language"&gt;
        Learn 5 words in Polish you didn't know yet
      &lt;/Activity&gt;
      &lt;Activity Type="Science"&gt;
        Write a simple program in C
      &lt;/Activity&gt;
      &lt;Activity Type="Sport"&gt;
        Go to the gym
      &lt;/Activity&gt;
    &lt;/Activities&gt;
  </code></pre>
  
  <p>Can you help me? I'm pretty stuck and probably missing something obvious. Thank you in advance.</p>