title: Looping through (and removing) items of a bound ComboBox
body: <p>I am new to WPF - and painfully aware of it. I have unsuccessfully searched for answers to this particular problem and am now seeking advice from my more knowledgeable peers!</p>
  
  <p><strong>The scenario</strong></p>
  
  <p>The application on which I am working allows users to either enter new records into a database, or amend existing ones.</p>
  
  <p>I have a form containing a bound ComboBox. It is populated from the database, which is accessed by a WPF service that exposes a DTO.</p>
  
  <p>From the UI perspective, the form has two modes:
  1. enter new record
  2. amend existing record</p>
  
  <p>The ComboBox in question appears in both cases, but the requirement is to have fewer options visible when the form is in 'amend' mode.</p>
  
  <p>What I am trying to do is loop through the ComboBox items when the form is in 'amend' mode and remove/hide the options that should not appear.</p>
  
  <p><strong>The XAML</strong></p>
  
  <pre><code>&lt;ComboBox x:Name="RecordType"  Grid.Column="1" Grid.Row="1"  Width="150"  HorizontalAlignment="Left" SelectedValue="{Binding Path=RecordTypeID,TargetNullValue=0}"/&gt;
  </code></pre>
  
  <p><strong>The code behind - and my (feeble!) attempts so far</strong></p>
  
  <pre><code>foreach (ComboBoxItem item in this.RecordType.Items)
  {
      if (IsApplicable(item.Content.ToString()) == false)
      {
          item.Visibility = Visibility.Hidden;
      }
  }
  </code></pre>
  
  <p>(NOTE: IsApplicable() is a simple method that compares the string it receives to a list of the options that are allowed to appear when the form is in 'amend' mode.)</p>
  
  <p><strong>The problem</strong></p>
  
  <p>As I'm sure many of you will already know ... cannot cast object of type DTO to type System.Windows.Controls.ComboBoxItem</p>
  
  <p><strong>The question(s)</strong></p>
  
  <p>Can I get at the string values in this, or a similar way? If so, how, please?</p>