/// <summary> /// Manage the sort of the items /// </summary> private void ItemsDataGrid_Sorting(object sender, DataGridSortingEventArgs e) { if (e.Column.SortDirection == null || e.Column.SortDirection == ListSortDirection.Descending) { // Sort by asc ItemsDataGrid.ItemsSource = EncycloDB.SortPreviousSearch(e.Column.SortMemberPath, ListSortDirection.Ascending); ItemsDataGrid.Columns[e.Column.DisplayIndex].SortDirection = ListSortDirection.Descending; // Inversed sort because the event will automatically inverse it again ActualSortDirection = ListSortDirection.Ascending; } else { // Sort by desc ItemsDataGrid.ItemsSource = EncycloDB.SortPreviousSearch(e.Column.SortMemberPath, ListSortDirection.Descending); ItemsDataGrid.Columns[e.Column.DisplayIndex].SortDirection = ListSortDirection.Ascending; // Inversed sort because the event will automatically inverse it again ActualSortDirection = ListSortDirection.Descending; } ActualSortedColumnIndex = e.Column.DisplayIndex; // Scroll to top after the sorting // source: https://social.msdn.microsoft.com/Forums/en-US/fdccbf75-bd1c-41c6-b209-71d6537603df/datagrid-event-after-columns-sorting Dispatcher.BeginInvoke((Action) delegate() { if (ItemsDataGrid.Items.Count > 0) { ItemsDataGrid.ScrollIntoView(ItemsDataGrid.Items[0]); } }, null); }
/// <summary> /// Search the items by differents filter /// </summary> private void BtnSearchItems_Click(object sender, RoutedEventArgs e) { // Force the correction of the levels before searching the items TbxItemLvlSearch_LostFocus(TbxItemLvlMinSearch, e); TbxItemLvlSearch_LostFocus(TbxItemLvlMaxSearch, e); int minLvl = Convert.ToInt32(TbxItemLvlMinSearch.Text); int maxLvl = Convert.ToInt32(TbxItemLvlMaxSearch.Text); string nameItem = TbxNameSearch.Text.Trim(); int[] idRarities = GetIntArrayOfSelectedElements(MscbxRarity.GetListElements()); int[] idTypes = GetIntArrayOfSelectedElements(MscbxType.GetListElements()); int[] idStats = GetIntArrayOfSelectedElements(MscbxStats.GetListElements()); ItemsDataGrid.ItemsSource = EncycloDB.SearchItems(minLvl, maxLvl, nameItem, idRarities, idTypes, idStats); ActualSortedColumnIndex = 0; // Reset the sort if (ItemsDataGrid.Items.Count > 0) { ItemsDataGrid.ScrollIntoView(ItemsDataGrid.Items[0]); } CloseAllPopup(); }