title: Dynamically adding items to WPF listbox
body: <p>I'm trying to build an application that the user points to a folder of PDF files.
  of Invoices, the program then parses the PDF files to find out wich ones contains an email address and wich ones don't. and this Is Where I'm stuck:</p>
  
  <p>I then want to add the file names to either the Listbox for print or the Listbox for email.</p>
  
  <p>I got all the other bits working, choosing the folder and parsing the PDF and adding the folder path to a textbox object.</p>
  
  <p>I then run a function:</p>
  
  <pre><code>private void listFiles(string selectedPath)
          {
              string[] fileEntries = Directory.GetFiles(selectedPath);
              foreach (string files in fileEntries)
              {
  
                  try
                  {
                      ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
                      using (PdfReader reader = new PdfReader(files))
                      {
                          string thePage = PdfTextExtractor.GetTextFromPage(reader, 1, its);
                          string[] theLines = thePage.Split('\n');
                          if (theLines[1].Contains("@"))
                          {
                             // System.Windows.MessageBox.Show("denne fil kan sendes som email til " + theLines[1], "Email!");
  
                          }
                          else
                          {
                              System.Windows.MessageBox.Show("denne fil skal Printes da " + theLines[1] + " ikke er en email", "PRINT!");
                          }
                      }
                  }
                  catch (Exception exc)
                  {
                      System.Windows.MessageBox.Show("FEJL!", exc.Message);
                  }
  
  
  
              }
          }
  </code></pre>
  
  <p>And it is in this function I want to be able to add the files to either Listbox.</p>
  
  <p>My XAML looks like this:</p>
  
  <pre><code>&lt;Grid.Resources&gt;
          &lt;local:ListofPrint x:Key="listofprint"/&gt;
  &lt;/Grid.Resources&gt;
  
  &lt;ListBox x:Name="lbxPrint" ItemsSource="{StaticResource listofprint}" HorizontalAlignment="Left" Height="140" Margin="24.231,111.757,0,0" VerticalAlignment="Top" Width="230"/&gt;
  </code></pre>
  
  <p>But I get the error: The name "ListofPrint" does not exist in the namespace "clr-namespace:test_app".</p>
  
  <p>the ListofPrint is here:</p>
  
  <pre><code>public class ListofPrint : ObservableCollection&lt;PDFtoPrint&gt;
      {
          public ListofPrint(string xfile)
          {
              Add(new PDFtoPrint(xfile));
          }
      }
  </code></pre>
  
  <p>I've been trying to get the hang of the documentation on MSDN and have read 10 different similar Questions on this site, but I guess my problem is that I don't know exactly what my problem is. first of it's a data binding problem but I basically copied the sample from the documentation to play with but that is what is giving me the trouble.</p>
  
  <p>Hopefully, someone here can explain to me the basics of data binding and how it corresponds to my ObservableCollection.</p>