0
私は、観察可能なコレクションをソートする方法を見つけるのに少し問題があります。私は現在、観察可能なコレクションを表示しているリストビューをリアルタイムで変更するために押されたボタンからのイベントを使用してこのプロセスをテストしようとしており、「ソート」コマンドを使用できないことを理解していますが、 "OrderBy"コマンド。私のコードは現在次のようになっています:UWP Visual Studio 2017 ObservableCollectionソート
public sealed partial class MainPage : Page
{
ObservableCollection<DataType> collection = new ObservableCollection<DataType>();
public MainPage()
{
this.InitializeComponent();
setupCollection();
}
public void setupCollection()
{
collection.Add(new DataType { times = "08:30" });
collection.Add(new DataType { times = "00:30" });
collection.Add(new DataType { times = "12:30" });
collection.Add(new DataType { times = "23:30" });
collection.Add(new DataType { times = "18:30" });
collection.Add(new DataType { times = "15:30" });
collection.Add(new DataType { times = "06:30" });
collection.Add(new DataType { times = "05:30" });
collection.Add(new DataType { times = "14:00" });
collection.Add(new DataType { times = "12:00" });
listview.ItemsSource = collection;
}
public class DataType
{
public string times { get; set; }
}
private void Button_Tapped(object sender, TappedRoutedEventArgs e)
{
collection = new ObservableCollection<DataType>(from i in DataType orderby i.times select i);
//collection.OrderBy(i.DataType > i.times);
}
}
誰かが私のコードを修正してアイテムを注文する方法を知っていますか?
どのようにOrderByを動作させることができますか? –
WPFでは、 'CollectionViewSource'を使用してこれを行うのは簡単ではないことに注意してください。 UWPで同様のことを達成するためのアイデアについては、https://stackoverflow.com/questions/34915276/uwp-observablecollection-sorting-and-groupingを参照してください。 –