title: How to sort in a WPF ListBox?
body: <p>The C# 4.0 WPF application, see the code below, shows on startup:  </p>
  
  <p><img src="https://i.stack.imgur.com/HK28Y.jpg" alt="Initial order of in &lt;code&gt;ListBox&lt;/code&gt;"></p>
  
  <p>abd after clicking the <strong>Sort</strong> button with <code>btnSort_Click()</code> click event handler:  </p>
  
  <p><img src="https://i.stack.imgur.com/ATAkN.jpg" alt="ListBox After Sorting"></p>
  
  <p>How can I sort in order aaa, bbb, ccc?  </p>
  
  <p>C# code:   </p>
  
  <pre><code>public MainWindow()
  {
    InitializeComponent();
  
    listBox1.Items.Add("ccc");
    listBox1.Items.Add("aaa");
    listBox1.Items.Add("bbb");
  }
  private void btnSort_Click(object sender, RoutedEventArgs e)
  {
    listBox1.Items.SortDescriptions.Add(
    new System.ComponentModel.SortDescription("Content",
         System.ComponentModel.ListSortDirection.Ascending));
  }
  private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  {
    listBox1.Items.RemoveAt
       (listBox1.Items.IndexOf(listBox1.SelectedItem));
  }
  </code></pre>
  
  <p>XAML:  </p>
  
  <pre><code>&lt;Window x:Class="WpfApp.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;ListBox Height="100" HorizontalAlignment="Left" Margin="8,43,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" MouseDoubleClick="listBox1_MouseDoubleClick" /&gt;
          &lt;Button Content="Sort" Height="23" HorizontalAlignment="Left" Margin="140,94,0,0" Name="btnSort" VerticalAlignment="Top" Width="75" Click="btnSort_Click" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Update:</strong><br>
  Well, I simply followed the article <a href="http://www.c-sharpcorner.com/resources/855/sorting-a-wpf-listbox-items.aspx" rel="noreferrer">"Sorting a WPF ListBox Items"</a>   </p>
  
  <p>So, what is the order by which I am sorting by a property "Content" and where is that property "Content", I wonder (tried to change it to arbitrary "fff" instead of "Content" having gotten the same, as in 2nd screenshot, results?  </p>