예제 #1
0
        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;
        }
    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;
    }
예제 #3
0
        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();
        }
    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();
    }
예제 #5
0
        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 == false)
            {
                IList <object> subItems = collectionViewGroup.GetItems();

                this.RegisterNodeCollectionChanged(
                    ( INotifyCollectionChanged )subItems,
                    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);
        }
예제 #6
0
        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);
        }
    private GeneratorNode SetupGroupHeaders( GroupConfiguration groupConfig, GeneratorNode actualNode )
    {
      if( groupConfig == null )
      {
        return new GeneratorNode( actualNode );
      }

      return this.NodeFactory.CreateHeadersFootersGeneratorNode( groupConfig.Headers, actualNode, null, null );
    }
        protected override Size MeasureOverride(Size availableSize)
        {
            Panel panel = this.GroupLevelIndicatorPaneHost;

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

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext != null)
            {
                ObservableCollection <GroupDescription> groupDescriptions = DataGridContext.GetGroupDescriptionsHelper(dataGridContext.Items);

                int leafGroupLevel = GroupLevelIndicatorPane.GetGroupLevel(this);

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

                // Ensure that the GroupLevel retrieved does not exceeds the number of group descriptions for the DataGridContext
                correctedGroupLevel = 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;
                }

                UIElementCollection children = panel.Children;
                int 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);
                }

                object 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;
                            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));
        }
예제 #9
0
 internal static void SetContainerGroupConfiguration( DependencyObject obj, GroupConfiguration value )
 {
   obj.SetValue( DataGridControl.ContainerGroupConfigurationProperty, value );
 }
    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;
    }