/***************************************************************************/ /// <summary> /// This can't be called until Window.OnContentRendered() is called, /// otherwise the adorner layer for the header items won't exist. /// "Although the logical tree can be traversed within the Window's constructor, /// the visual tree is empty until the Window undergoes layout at least once." /// </summary> public void SortOnce() { Items.SortDescriptions.Clear(); /// Clear all adorners. foreach (KeyValuePair <string, SortDirectionAdorner> ThisPair in m_LastHeaderAdornerDictionary) { TaggedGridViewColumn ThisColumn = m_ColumnDictionary[ThisPair.Key]; GridViewColumnHeader ThisHeader = (ThisColumn.Header as GridViewColumnHeader); AdornerLayer ThisLayer = AdornerLayer.GetAdornerLayer(ThisHeader); if (ThisLayer != null) { ThisLayer.Remove(ThisPair.Value); } } m_LastHeaderAdornerDictionary.Clear(); /// Add new adorners. foreach (ColumnLayout.SortDesc ThisDesc in m_SavedLayout.m_aColumnSortOrderList) { TaggedGridViewColumn ThisColumn = m_ColumnDictionary[ThisDesc.m_strTag]; GridViewColumnHeader ThisHeader = (ThisColumn.Header as GridViewColumnHeader); SortDirectionAdorner NewAdorner = new SortDirectionAdorner(ThisHeader, Items.SortDescriptions.Count, ThisDesc.m_bSortAscending); AdornerLayer ThisLayer = AdornerLayer.GetAdornerLayer(ThisHeader); if (ThisLayer != null) { ThisLayer.Add(NewAdorner); } m_LastHeaderAdornerDictionary.Add(ThisColumn.Tag, NewAdorner); string strSortProperty = (ThisColumn.DisplayMemberBinding as Binding).Path.Path; Items.SortDescriptions.Add(new SortDescription(strSortProperty, ThisDesc.m_bSortAscending ? ListSortDirection.Ascending : ListSortDirection.Descending)); } return; }
/***************************************************************************/ protected void OnHeaderClick(object sender, RoutedEventArgs e) { GridViewColumnHeader ThisHeader = (sender as GridViewColumnHeader); TaggedGridViewColumn ThisColumn = (ThisHeader.Column as TaggedGridViewColumn); /// Simply invert the toggle if it is the same column as the main. if (ThisColumn.Tag == m_SavedLayout.m_aColumnSortOrderList[0].m_strTag) { m_SavedLayout.m_aColumnSortOrderList[0].m_bSortAscending = !m_SavedLayout.m_aColumnSortOrderList[0].m_bSortAscending; } /// Otherwise copy it and overwrite everything. else { bool bSortAscending = m_SavedLayout.m_aColumnSortOrderList[0].m_bSortAscending; m_SavedLayout.m_aColumnSortOrderList.Clear(); m_SavedLayout.m_aColumnSortOrderList.Add(new ColumnLayout.SortDesc(ThisColumn.Tag, bSortAscending)); } SortOnce(); return; }
/***************************************************************************/ public void SaveLayout() { if (m_SavedLayout == null) { throw new Exception("A layout object must be linked to this PersistentDetailedListView."); } m_SavedLayout.m_astrColumnDisplayOrderList.Clear(); //m_ColumnDescDictionary.Clear(); for (int iIndex = 0; iIndex < m_wndGridView.Columns.Count; iIndex++) { TaggedGridViewColumn ThisColumn = (m_wndGridView.Columns[iIndex] as TaggedGridViewColumn); m_SavedLayout.m_astrColumnDisplayOrderList.Add(ThisColumn.Tag); /// Save the details without erasing the dictionary (all of it will be saved to disk somehow). ColumnLayout.ColumnDesc ThisDesc = null; if (m_SavedLayout.m_ColumnDescDictionary.TryGetValue(ThisColumn.Tag, out ThisDesc)) { ThisDesc.m_fWidth = ThisColumn.Width; } } return; }