Exemple #1
0
        private void GetClassStudents()
        {
            StoreDB db = new StoreDB();

            try
            {
                DataItems = db.GetClassStudents();
            }
            catch (Exception e)
            {
                log.Error("In CSViewModel..GetClassStudents: " + e.StackTrace);
                Environment.Exit(-1);
            }

            //https://wpftutorial.net/DataViews.html
            //https://stackoverflow.com/questions/8597824/listbox-groupstyle-display-how-to-design-a-group-name
            //https://stackoverflow.com/questions/20188132/how-to-correctly-bind-update-a-datagrid-with-a-collectionviewsource
            //The sorting technique explained above is really simple, but also quite slow for a large amount of data,
            //because it internally uses reflection. But there is an alternative, more performant way to do sorting by providing a custom sorter.
            //when DataItems points to a new object, we need to GetDefaultView(DataItems) and add Grouping
            //CSSelectionView ItemsSource="{Binding DataItems}"; We dont need to bind to DataItems1
            _customerView = CollectionViewSource.GetDefaultView(DataItems);
            if (_customerView.GroupDescriptions == null || _customerView.GroupDescriptions.Count == 0)
            {
                _customerView.GroupDescriptions.Add(new PropertyGroupDescription("Grouping"));
                _customerView.SortDescriptions.Add(new SortDescription("Grouping", ListSortDirection.Ascending));
                _customerView.SortDescriptions.Add(new SortDescription("StudentName", ListSortDirection.Ascending));
            }

            if (db.hasError)
            {
                App.Messenger.NotifyColleagues("SetStatus", db.errorMessage);
            }
        }