The WPF C # 4.0 application, see the code below, shows at startup:

abd after clicking the Sort button with btnSort_Click() click event handler:

How can I sort in order aaa, bbb, ccc?
C # 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)); }
XAML:
<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"> <Grid> <ListBox Height="100" HorizontalAlignment="Left" Margin="8,43,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" MouseDoubleClick="listBox1_MouseDoubleClick" /> <Button Content="Sort" Height="23" HorizontalAlignment="Left" Margin="140,94,0,0" Name="btnSort" VerticalAlignment="Top" Width="75" Click="btnSort_Click" /> </Grid> </Window>
Update:
Well, I just went for the article Sorting ListView WPF List Items
So, what is the order in which I sort by the "Content" property, and where is the "Content" property, I wonder (I tried to change it to an arbitrary "fff" instead of "Content", getting the same results as in the second screenshot, ?
source share