2
我在列表視圖中實現了對this article的排序。窗口打開時,如何讓我的列表進入默認排序?我想:如何對默認排序wpf listview
public MainWindow()
{
InitializeComponent();
SortCustomerList("CustomerName", ListSortDirection.Ascending);
}
...但我發現了「異常已通過調用的目標引發異常」 ......以「未設置爲一個對象的實例對象引用的內部異常。 「
[編輯]我移動調用按照建議排序到加載事件,但我仍然得到例外?以下是排序方法和加載事件的樣子:
private void SortCustomerList(string sortBy, ListSortDirection direction)
{
ICollectionView dataView = CollectionViewSource.GetDefaultView(customersListView.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}
private void mainWindow_Loaded(object sender, RoutedEventArgs e)
{
SortCustomerList("CustomerName", ListSortDirection.Ascending);
}
它在Clear()方法上失敗。
感謝您的任何建議。
謝謝。我嘗試將排序方法調用移動到加載的事件,但我仍然遇到異常。 – CraigV 2011-01-08 19:25:17