protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e) { base.OnIsKeyboardFocusWithinChanged(e); bool newValue = ( bool )e.NewValue; if (newValue == true) { DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this); if (dataGridContext != null) { object item = dataGridContext.GetItemFromContainer(this); if ((item != null) && (dataGridContext.InternalCurrentItem != item)) { try { dataGridContext.SetCurrent(item, null, -1, dataGridContext.CurrentColumn, true, true, false); } catch (DataGridException) { // We swallow the exception if it occurs because of a validation error or Cell was read-only or // any other GridException. } } } } }
protected virtual void PrepareContainer(DataGridContext dataGridContext, object item) { if (m_isContainerPrepared) { Debug.Fail("A GroupHeaderControl can't be prepared twice, it must be cleaned before PrepareContainer is called again"); } Group group = null; DataGridContext gridContext = DataGridControl.GetDataGridContext(this); if (gridContext != null) { object dataItem = gridContext.GetItemFromContainer(this); if (dataItem != null) { group = gridContext.GetGroupFromItem(dataItem); } } this.SetGroup(group); m_itemContainerManager.Prepare(gridContext, item); m_isContainerPrepared = true; }
private FixedCellPanel LocateFixedCellPanel(DependencyObject obj) { DependencyObject child; FixedCellPanel foundPanel; for (int i = VisualTreeHelper.GetChildrenCount(obj) - 1; i >= 0; i--) { child = VisualTreeHelper.GetChild(obj, i); foundPanel = child as FixedCellPanel; if (foundPanel != null) { return(foundPanel); } foundPanel = this.LocateFixedCellPanel(child); if (foundPanel != null) { // The FixedCellPanel found can be one of the recycled container in the visual tree DataGridContext dataGridContext = DataGridControl.GetDataGridContext(foundPanel); if (dataGridContext != null) { if (dataGridContext.GetItemFromContainer(foundPanel) != null) { return(foundPanel); } } } } return(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)); }