title: Add Items to ComboBox Programmatically
body: <p>I have been working with WPF all of 2 days, coming from ASP.NET so bear with me!</p>
  
  <p>I am populating a ComboBox with xml filenames from a directory and adding a icon to each item. I have everything working just fine but I am wondering if there is a "better", more "efficient" way of doing this. As I stated, I am just getting started with WPF and I want to go about things the "right" way. My working code is below, can or should I be going about this a different way? Thanks in advance for any pointers!</p>
  
  <pre><code>&lt;ComboBox Height="24" HorizontalAlignment="Left" Margin="153,138,0,0" Name="cmbFiles" VerticalAlignment="Top" Width="200" //&gt;
  </code></pre>
  
  
  
  <pre><code>private void FillSrFileCombo()
  {
      string[] dirFiles = Directory.GetFiles(@"D:\TestFiles", "*.xml");
  
      foreach (string datei in dirFiles)
      {
          string fileName = System.IO.Path.GetFileName(datei);
  
          System.Windows.Controls.StackPanel stkPanel = new StackPanel();
          stkPanel.Orientation = Orientation.Horizontal;
          cmbFiles.Items.Add(stkPanel);
  
          System.Windows.Controls.Image cboIcon = new Image();
          BitmapImage bitMap = new BitmapImage();
          bitMap.BeginInit();
          bitMap.UriSource = new Uri(@"tag.jpg", UriKind.Relative);
          bitMap.EndInit();
          cboIcon.Source = bitMap;
          cboIcon.Height = 15;
          stkPanel.Children.Add(cboIcon);
  
          System.Windows.Controls.TextBlock cboText = new TextBlock();
          cboText.Text = " - " + fileName;
          stkPanel.Children.Add(cboText);
      }
  }
  </code></pre>