C#4.0 WPFアプリケーション(以下のコードを参照)は、起動時に表示されます。
クリックイベントハンドラー で[並べ替え]ボタンをクリックした後のabd :btnSort_Click()
aaa、bbb、cccの順に並べ替えるにはどうすればよいですか?
C#コード:
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>
更新:
まあ、私は単に「WPFリストボックスアイテムの並べ替え」の記事に従いました
それで、私がプロパティ「Content」でソートしている順序は何ですか、そしてそのプロパティ「Content」はどこにあるのでしょうか(「Content」が同じになるのではなく、任意の「fff」に変更しようとしました) 2番目のスクリーンショット、結果?