Пример #1
0
        private void UpdateMetadata()
        {
            var metadata = CreateMetadata();

            if (Metadata != null && Metadata == metadata)
            {
                return;
            }

            Debug.WriteLine("UpdateMetadata()");
            using (_updateMonitor.Enter())
                Metadata = metadata;
        }
Пример #2
0
        private void ApplyMetadata(DataGridMetadata metadata)
        {
            if (metadata == null)
            {
                return;
            }

            Debug.WriteLine("ApplyMetadata()");
            using (_applyMonitor.Enter())
            {
                int  columnCount           = AssociatedObject.Columns.Count;
                var  collectionView        = AssociatedObject.Items as ICollectionView;
                bool clearSortDescriptions = true;

                foreach (var columnMetadata in metadata.ColumnMetadata)
                {
                    if (columnMetadata.Index >= columnCount)
                    {
                        continue;
                    }

                    var column = AssociatedObject.Columns[columnMetadata.Index];

                    if (columnMetadata.DisplayIndex >= 0 && columnMetadata.DisplayIndex < columnCount)
                    {
                        column.DisplayIndex = columnMetadata.DisplayIndex;
                    }

                    column.Visibility    = columnMetadata.Visibility;
                    column.SortDirection = columnMetadata.SortDirection;
                    column.Width         = new DataGridLength(columnMetadata.Width);

                    if (collectionView == null || column.SortDirection == null)
                    {
                        continue;
                    }

                    if (clearSortDescriptions)
                    {
                        collectionView.SortDescriptions.Clear();
                        clearSortDescriptions = false;
                    }

                    var sortDescription = new SortDescription(column.SortMemberPath, column.SortDirection.Value);
                    collectionView.SortDescriptions.Add(sortDescription);
                }
            }
        }
Пример #3
0
        private void OnDataGridLoaded(object sender, RoutedEventArgs e)
        {
            // capture default values from xaml before applying any
            _defaultMetadata         = CreateMetadata();
            _isLoaded                = true;
            AssociatedObject.Loaded -= OnDataGridLoaded;

            if (Metadata == null)
            {
                UpdateMetadata();
            }
            else
            {
                ApplyMetadata(Metadata);
            }
        }
Пример #4
0
        private DataGridMetadata CreateMetadata()
        {
            var metadata = new DataGridMetadata();

            for (int index = 0; index < AssociatedObject.Columns.Count; index++)
            {
                var column         = AssociatedObject.Columns[index];
                var columnMetadata = new DataGridColumnMetadata
                {
                    Index         = index,
                    DisplayIndex  = column.DisplayIndex,
                    Visibility    = column.Visibility,
                    Width         = column.ActualWidth,
                    SortDirection = column.SortDirection,
                    Header        = column.Header == null ? "Column " + index : column.Header.ToString()
                };
                metadata.ColumnMetadata.Add(columnMetadata);
            }

            return(metadata);
        }