title: Sorting a combobox purely in XAML
body: <p>I'm surprised that no one has asked this before here... well, at least I haven't found an answer here or anywhere else, actually.</p>
  
  <p>I have a ComboBox that is databound to an ObservableCollection.  Everything worked great until the guys wanted the contents sorted.  No problem -- I end up changing the simple property out:</p>
  
  <pre><code>public ObservableCollection&lt;string&gt; CandyNames { get; set; } // instantiated in constructor
  </code></pre>
  
  <p>for something like this:</p>
  
  <pre><code>private ObservableCollection&lt;string&gt; _candy_names; // instantiated in constructor
  public ObservableCollection&lt;string&gt; CandyNames
  {
      get {
          _candy_names = new ObservableCollection&lt;string&gt;(_candy_names.OrderBy( i =&gt; i));
          return _candy_names;
      }
      set {
          _candy_names = value;
      }
  }
  </code></pre>
  
  <p>This post is really two questions in one:</p>
  
  <ol>
  <li>How can I sort a simple ComboBox of strings in XAML <strong>only</strong>.  I have researched this and can only find info about a SortDescription class, and <a href="http://www.galasoft.ch/mydotnet/articles/article-2007081301.aspx" rel="noreferrer">this is the closest implementation I could find</a>, but it wasn't for a ComboBox.</li>
  <li>Once I implemented the sorting in code-behind, it my databinding was broken; when I added new items to the ObservableCollection, the ComboBox items didn't update!  I don't see how that happened, because I didn't assign a name to my ComboBox and manipulate it directly, which is what typically breaks the binding.</li>
  </ol>
  
  <p>Thanks for your help!</p>