public GroupGeneratorNode(CollectionViewGroup group, GeneratorNode parent, GroupConfiguration groupConfig)
            : base(parent)
        {
            Debug.Assert(group != null, "group cannot be null for GroupGeneratorNode");
            Debug.Assert(groupConfig != null);

            m_group       = group;
            m_groupConfig = groupConfig;
        }
        static GroupConfiguration()
        {
            GroupConfiguration.HeadersProperty = GroupConfiguration.HeadersPropertyKey.DependencyProperty;
            GroupConfiguration.FootersProperty = GroupConfiguration.FootersPropertyKey.DependencyProperty;

            DefaultHeaderTemplate = new GroupHeaderFooterItemTemplate();
            DefaultHeaderTemplate.VisibleWhenCollapsed = true;
            DefaultHeaderTemplate.Template             = new DataTemplate();
            DefaultHeaderTemplate.Template.VisualTree  = new FrameworkElementFactory(typeof(GroupHeaderControl));
            DefaultHeaderTemplate.Template.Seal();
            DefaultHeaderTemplate.Seal();

            DefaultGroupConfiguration = new GroupConfiguration();
            DefaultGroupConfiguration.AddDefaultHeadersFooters();
            DefaultGroupConfiguration.Freeze();
        }
Beispiel #3
0
        private readonly WeakReference m_dataGridControl; //null

        #endregion

        public GeneratorNode CreateGroupGeneratorNode(
            CollectionViewGroup collectionViewGroup,
            GeneratorNode parent,
            GeneratorNode previous,
            GeneratorNode next,
            GroupConfiguration groupConfig)
        {
            Debug.Assert(collectionViewGroup != null, "collectionViewGroup cannot be null for CreateGroupGeneratorNode()");

            GroupGeneratorNode node = new GroupGeneratorNode(collectionViewGroup, parent, groupConfig);

            if (previous != null)
            {
                previous.Next = node;
            }
            node.Previous = previous;

            if (next != null)
            {
                next.Previous = node;
            }
            node.Next = next;

            node.IsExpanded = groupConfig.InitiallyExpanded;

            if (!collectionViewGroup.IsBottomLevel)
            {
                this.RegisterNodeCollectionChanged(
                    ( INotifyCollectionChanged )collectionViewGroup.GetItems(),
                    new NotifyCollectionChangedEventHandler(node.OnCollectionChanged));

                node.CollectionChanged += m_groupsChangedHandler;
            }

            node.ExpansionStateChanged += m_expansionStateChangedHandler;
            node.IsExpandedChanging    += m_isExpandedChangingHandler;
            node.IsExpandedChanged     += m_isExpandedChangedHandler;

            node.AdjustItemCount(node.ItemCount);

            node.BuildNamesTree();

            return(node);
        }
        internal static GroupConfiguration GetGroupConfiguration(DataGridContext dataGridContext, ObservableCollection <GroupDescription> groupDescriptions, GroupConfigurationSelector groupConfigSelector, int groupLevel, CollectionViewGroup collectionViewGroup)
        {
            if (dataGridContext == null)
            {
                throw new ArgumentNullException("dataGridContext");
            }

            if (groupDescriptions == null)
            {
                throw new ArgumentNullException("groupDescriptions");
            }

            if (groupLevel >= groupDescriptions.Count)
            {
                throw new ArgumentException("The specified group level is greater than the number of GroupDescriptions in the DataGridContext.", "groupLevel");
            }

            GroupDescription groupDescription = groupDescriptions[groupLevel];

            GroupConfiguration       retval = null;
            DataGridGroupDescription dataGridGroupDescription = groupDescription as DataGridGroupDescription;

            if ((dataGridGroupDescription != null) && (dataGridGroupDescription.GroupConfiguration != null))
            {
                retval = dataGridGroupDescription.GroupConfiguration;
            }
            else if (groupConfigSelector != null)
            {
                retval = groupConfigSelector.SelectGroupConfiguration(groupLevel, collectionViewGroup, groupDescription);
            }

            if (retval == null)
            {
                retval = dataGridContext.DefaultGroupConfiguration;
            }

            if (retval == null)
            {
                retval = GroupConfiguration.DefaultGroupConfiguration;
            }

            return(retval);
        }
        protected override Size MeasureOverride(Size availableSize)
        {
            var panel           = this.GroupLevelIndicatorPaneHost;
            var dataGridContext = DataGridControl.GetDataGridContext(this);

            if ((panel == null) || (dataGridContext == null))
            {
                return(base.MeasureOverride(availableSize));
            }

            var groupDescriptions = DataGridContext.GetGroupDescriptionsHelper(dataGridContext.Items);
            var leafGroupLevel    = GroupLevelIndicatorPane.GetGroupLevel(this);

            // If Indented is true (default), we use the total groupDescriptions.Count for this DataGridContext
            var correctedGroupLevel = (this.Indented == true) ? groupDescriptions.Count : leafGroupLevel;

            // Ensure that the GroupLevel retrieved does not eNequeos the number of group descriptions for the DataGridContext
            correctedGroupLevel = System.Math.Min(correctedGroupLevel, groupDescriptions.Count);

            // Then finally, if the GroupLevel is -1, then indent at maximum.
            if (correctedGroupLevel == -1)
            {
                correctedGroupLevel = groupDescriptions.Count;
            }

            if ((correctedGroupLevel > 0) && (this.AreGroupsFlattened))
            {
                correctedGroupLevel = (this.Indented) ? 1 : 0;
            }

            var children      = panel.Children;
            var childrenCount = children.Count;

            // If we need to add/remove GroupLevelIndicators from the panel
            if (correctedGroupLevel != childrenCount)
            {
                // When grouping change, we take for granted that the group deepness will change,
                // so we initialize DataContext of the margin only in there.

                // Clear all the panel's children!
                children.Clear();

                // Create 1 group margin content presenter for each group level
                for (int i = correctedGroupLevel - 1; i >= 0; i--)
                {
                    GroupLevelIndicator groupMargin = new GroupLevelIndicator();
                    groupMargin.DataContext = dataGridContext.GroupLevelDescriptions[i];
                    children.Insert(0, new GroupLevelIndicator());
                }

                childrenCount = correctedGroupLevel;
                this.SetCurrentIndicatorCount(childrenCount);

                this.InvalidateGroupLevelIndicatorPaneHostPanelMeasure();
            }

            var item = dataGridContext.GetItemFromContainer(this);

            for (int i = 0; i < childrenCount; i++)
            {
                GroupLevelIndicator groupMargin = children[i] as GroupLevelIndicator;

                CollectionViewGroup groupForIndicator = GroupLevelIndicatorPane.GetCollectionViewGroupHelper(
                    dataGridContext, groupDescriptions, item, i);

                GroupConfiguration groupLevelConfig = GroupConfiguration.GetGroupConfiguration(
                    dataGridContext, groupDescriptions, dataGridContext.GroupConfigurationSelector, i, groupForIndicator);

                if (groupLevelConfig != null)
                {
                    Binding groupLevelIndicatorStyleBinding = BindingOperations.GetBinding(groupMargin, GroupLevelIndicator.StyleProperty);

                    if ((groupLevelIndicatorStyleBinding == null) || (groupLevelIndicatorStyleBinding.Source != groupLevelConfig))
                    {
                        groupLevelIndicatorStyleBinding        = new Binding("GroupLevelIndicatorStyle");
                        groupLevelIndicatorStyleBinding.Source = groupLevelConfig;

                        // Use a Converter to manage groupLevelConfig.GroupLevelIndicatorStyle == null
                        // so that an implicit syle won't be overriden by a null style.
                        groupLevelIndicatorStyleBinding.Converter = new GroupLevelIndicatorConverter();

                        groupLevelIndicatorStyleBinding.ConverterParameter = groupMargin;
                        groupMargin.SetBinding(GroupLevelIndicator.StyleProperty, groupLevelIndicatorStyleBinding);
                    }
                }
                else
                {
                    groupMargin.ClearValue(GroupLevelIndicator.StyleProperty);
                }

                // If the ShowIndicators property is False or there is already leafGroupLevel GroupLevelIndicators in the panel,
                // the current newGroupMargin must be hidden.
                if ((!GroupLevelIndicatorPane.GetShowIndicators(this)) || ((i >= leafGroupLevel) && (leafGroupLevel != -1)))
                {
                    groupMargin.Visibility = Visibility.Hidden;
                }
                else
                {
                    groupMargin.Visibility = Visibility.Visible;
                }
            }

            return(base.MeasureOverride(availableSize));
        }