title: 2 ObservableCollections 1 Combobox WPF
body: <p>I have a WPF application, that establishes a connection to a different computer. Inside my application, I have a combo box, where the user can enter a hostname of a computer and then connect to this computer. Now once the connection was established the hostname the user entered gets saved into an Observable Collection which is bound to the combo box, so the next time he wants to connect to the same host, he can choose it directly from the combo box.</p>
  
  <p>I have implemented a favorite list. which is a separate observable collection that I too want to bind to the same combo box, so the user can either choose either a favorite or a history item.</p>
  
  <p>In the dropdown list of the combo box I would like 2 Groupings with a Header, something like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    [Favorites]
           My Favourite Host | myfavhost.com
           My 2nd Fav | my2ndfav.com
           Secretly My Fav | secretlymyfav.com
      [History]
           hostioncevisited.com
           whyamihere.com
           thanksforhelping.com
  
  </code></pre>
  
  <p>Now I don't really know how to go about that. Is there a way to bind multiple items sources to the combobox, or would I have to merge the two observable collections before I bind them to the combo box?</p>
  
  <p>These are my observable collections</p>
  
  <pre class="lang-cs prettyprint-override"><code>public ObservableCollection&lt;string&gt; HistoryItems { get; set; } = new ObservableCollection&lt;string&gt;();
  
  public static ObservableCollection&lt;FavoriteItem&gt; FavoriteItems { get; set; } = new ObservableCollection&lt;FavoriteItem&gt;();
  
  </code></pre>
  
  <p>Here is my FavoriteItem Class</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class FavoriteItem : INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
          private string hostName;
          private string description;
  
          public FavoriteItem(){}
          public FavoriteItem(string _hostName, string _description)
          {
              hostName = _hostName;
              description = _description;
          }
  
          public string Hostname
          {
              get { return hostName; }
              set
              {
                  hostName = value;
                  OnPropertyChanged("Hostname");
              }
          }
  
          public string Description
          {
              get { return description; }
              set
              {
                  description = value;
                  OnPropertyChanged("Description");
              }
          }
  
          protected void OnPropertyChanged(string name)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(name));
              }
          }
  
          public override string ToString()
          {
              return string.Format("{0} | {1}", description, hostName);
          }
      }
  </code></pre>
  
  <p>Here is the XAML for the combo box</p>
  
  <p>XAML</p>
  
  <pre><code>&lt;ComboBox Name="cbHostName" Style="{StaticResource ComboBoxLarge}" Text="{Binding HostName}" ItemsSource="{Binding HistoryItems}" 
                            MinWidth="300" MaxWidth="300" IsEditable="True" Margin="0,0,15,0" VerticalAlignment="Center" materialDesign:HintAssist.Hint="Computer, IP or HostProfileName"/&gt;
  </code></pre>
  
  <pre><code>
  </code></pre>