Пример #1
0
        /// <summary>
        /// Autosizes a single column.
        /// </summary>
        /// <param name="sender">The Object that generated the routed command.</param>
        /// <param name="e">The executed routed event data.</param>
        void OnFitColumn(Object sender, ExecutedRoutedEventArgs e)
        {
            /// This will extract from the event the column header that was the original source of the event and resize the column.
            ColumnViewColumnHeader columnViewColumnHeader = e.OriginalSource as ColumnViewColumnHeader;

            if (columnViewColumnHeader != null)
            {
                if (columnViewColumnHeader.Role != ColumnViewColumnHeaderRole.Padding)
                {
                    this.AutoSizeColumn(columnViewColumnHeader.Column);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles a routed command to sort the column.
        /// </summary>
        /// <param name="sender">The Object that generated the event.</param>
        /// <param name="routedEventArgs">The routed event arguments.</param>
        void OnHeaderClick(Object sender, RoutedEventArgs routedEventArgs)
        {
            // Extract from the command arguments the column header that generated a request to be autosized and then resize the column.
            ColumnViewColumnHeader columnViewColumnHeader = routedEventArgs.OriginalSource as ColumnViewColumnHeader;
            ColumnViewColumn       columnViewColumn       = columnViewColumnHeader.Column;

            // This will prevent each change we make to the view from triggering an update of the viewed data.
            using (this.consumerCollection.View.DeferRefresh())
            {
                // Clear out the existing sort order from the view.
                this.consumerCollection.View.SortDescriptions.Clear();

                // Clear the sort order for the other columns.
                foreach (ColumnViewColumn siblingColumn in this.ColumnView.Columns)
                {
                    if (siblingColumn != columnViewColumn)
                    {
                        siblingColumn.SortDirection = SortDirection.None;
                    }
                }

                // If a DisplayMemberBinding exists for this column, we'll use that binding to find the property used to populate this column.
                Binding binding = columnViewColumn.DisplayMemberBinding as Binding;
                if (binding != null)
                {
                    // This will toggle the sort order for this column (or select Ascending if the sort order hasn't been set) and set the corresonding sort order in
                    // the collection view.
                    columnViewColumn.SortDirection = columnViewColumn.SortDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
                    ListSortDirection listSortDirection =
                        columnViewColumn.SortDirection == SortDirection.Descending ?
                        ListSortDirection.Descending :
                        ListSortDirection.Ascending;
                    this.consumerCollection.View.SortDescriptions.Add(new SortDescription(binding.Path.Path, listSortDirection));
                }
            }
        }