This commit is contained in:
chinboy
2025-01-20 11:38:39 +08:00
committed by CHINBOY
parent d09e9db223
commit 946ae4b5ca
13 changed files with 175 additions and 187 deletions
@@ -42,7 +42,9 @@ public interface IDataGridCollectionViewFactory
/// <summary>
/// DataGrid-readable view over an IEnumerable.
/// </summary>
public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridEditableCollectionView, IList,
public sealed class DataGridCollectionView : IDataGridCollectionView,
IDataGridEditableCollectionView,
IList,
INotifyPropertyChanged
{
/// <summary>
@@ -184,22 +186,13 @@ public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridE
/// </summary>
private IEnumerator _trackingEnumerator;
/// <summary>
/// Helper constructor that sets default values for isDataSorted and isDataInGroupOrder.
/// </summary>
/// <param name="source">The source for the collection</param>
public DataGridCollectionView(IEnumerable source)
: this(source, false /*isDataSorted*/, false /*isDataInGroupOrder*/)
{
}
/// <summary>
/// Initializes a new instance of the DataGridCollectionView class.
/// </summary>
/// <param name="source">The source for the collection</param>
/// <param name="isDataSorted">Determines whether the source is already sorted</param>
/// <param name="isDataInGroupOrder">Whether the source is already in the correct order for grouping</param>
public DataGridCollectionView(IEnumerable source, bool isDataSorted, bool isDataInGroupOrder)
public DataGridCollectionView(IEnumerable source, bool isDataSorted = false, bool isDataInGroupOrder = false)
{
_culture = CultureInfo.CurrentUICulture;
_sourceCollection = source ?? throw new ArgumentNullException(nameof(source));
@@ -2572,15 +2565,18 @@ public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridE
private void CopySourceToInternalList()
{
_internalList = new List<object>();
IEnumerator enumerator = SourceCollection.GetEnumerator();
while (enumerator.MoveNext())
var enumerator = SourceCollection.GetEnumerator();
try
{
_internalList.Add(enumerator.Current);
while (enumerator.MoveNext())
{
_internalList.Add(enumerator.Current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
((IDisposable)enumerator).Dispose();
}
/// <summary>
@@ -3234,8 +3230,8 @@ public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridE
// if we are paging, we may have to fire another notification for the item
// that needs to be removed for the one we added on this page.
if (PageSize > 0 && !OnLastLocalPage &&
(((IsGrouping && removeNotificationItem != null) ||
(!IsGrouping && (PageIndex + 1) * PageSize > InternalIndexOf(addedItem)))))
((IsGrouping && removeNotificationItem != null) ||
(!IsGrouping && (PageIndex + 1) * PageSize > InternalIndexOf(addedItem))))
{
if (removeNotificationItem != null && removeNotificationItem != addedItem)
{
@@ -3720,7 +3716,7 @@ public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridE
/// <param name="newPosition">New CurrentPosition</param>
private void SetCurrent(object? newItem, int newPosition)
{
int count = (newItem != null) ? 0 : (IsEmpty ? 0 : Count);
int count = newItem != null ? 0 : (IsEmpty ? 0 : Count);
SetCurrent(newItem, newPosition, count);
}
@@ -4264,7 +4260,7 @@ public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridE
{
return index;
}
else if (result > 0)
if (result > 0)
{
min = index + 1;
}
@@ -88,7 +88,7 @@ internal class DataGridColumnCollection : ObservableCollection<DataGridColumn>
throw DataGridError.DataGrid.CannotChangeColumnCollectionWhileAdjustingDisplayIndexes();
}
_owningGrid.OnClearingColumns();
_owningGrid.NotifyClearingColumns();
for (var columnIndex = 0; columnIndex < ItemsInternal.Count; columnIndex++)
{
// Detach the column...
@@ -134,7 +134,7 @@ internal class DataGridColumnCollection : ObservableCollection<DataGridColumn>
// get the new current cell coordinates
DataGridCellCoordinates newCurrentCellCoordinates =
_owningGrid.OnInsertingColumn(columnIndex, dataGridColumn);
_owningGrid.NotifyInsertingColumn(columnIndex, dataGridColumn);
// insert the column into our internal list
ItemsInternal.Insert(columnIndexWithFiller, dataGridColumn);
@@ -146,7 +146,7 @@ internal class DataGridColumnCollection : ObservableCollection<DataGridColumn>
}
// continue with the base insert
_owningGrid.HandleInsertedColumnPreNotification(dataGridColumn);
_owningGrid.NotifyInsertedColumnPreNotification(dataGridColumn);
_owningGrid.NotifyColumnCollectionChangedPreNotification(true /*columnsGrew*/);
if (dataGridColumn != RowGroupSpacerColumn)
@@ -65,7 +65,7 @@ public abstract class DataGridBoundColumn : DataGridColumn
// Apply the new Binding to existing rows in the DataGrid
if (OwningGrid != null)
{
OwningGrid.OnColumnBindingChanged(this);
OwningGrid.NotifyColumnBindingChanged(this);
}
}
@@ -112,7 +112,7 @@ public abstract class DataGridColumn : AvaloniaObject
internal bool HasHeaderCell => _headerCell != null;
internal DataGridColumnHeader? HeaderCell
internal DataGridColumnHeader HeaderCell
{
get
{
@@ -158,7 +158,7 @@ public abstract class DataGridColumn : AvaloniaObject
if (change.Property == IsVisibleProperty)
{
OwningGrid?.OnColumnVisibleStateChanging(this);
OwningGrid?.NotifyColumnVisibleStateChanging(this);
var isVisible = change.GetNewValue<bool>();
if (_headerCell != null)
@@ -166,7 +166,7 @@ public abstract class DataGridColumn : AvaloniaObject
_headerCell.IsVisible = isVisible;
}
OwningGrid?.OnColumnVisibleStateChanged(this);
OwningGrid?.NotifyColumnVisibleStateChanged(this);
NotifyPropertyChanged(change.Property.Name);
}
else if (change.Property == WidthProperty)
@@ -187,7 +187,7 @@ public abstract class DataGridColumn : AvaloniaObject
{
SetWidthInternalNoCallback(width);
IsInitialDesiredWidthDetermined = false;
grid.OnColumnWidthChanged(this);
grid.NotifyColumnWidthChanged(this);
}
else
{
@@ -249,7 +249,7 @@ public abstract class DataGridColumn : AvaloniaObject
set
{
CanUserResizeInternal = value;
OwningGrid?.OnColumnCanUserResizeChanged(this);
OwningGrid?.NotifyColumnCanUserResizeChanged(this);
}
}
@@ -344,7 +344,7 @@ public abstract class DataGridColumn : AvaloniaObject
}
// Will throw an error if a visible frozen column is placed inside a non-frozen area or vice-versa.
OwningGrid.OnColumnDisplayIndexChanging(this, value);
OwningGrid.NotifyColumnDisplayIndexChanging(this, value);
_displayIndexWithFiller = value;
try
{
@@ -452,7 +452,7 @@ public abstract class DataGridColumn : AvaloniaObject
{
if (value != _isReadOnly)
{
OwningGrid?.OnColumnReadOnlyStateChanging(this, value);
OwningGrid?.NotifyColumnReadOnlyStateChanging(this, value);
_isReadOnly = value;
}
}
@@ -480,7 +480,7 @@ public abstract class DataGridColumn : AvaloniaObject
_maxWidth = value;
if (OwningGrid != null)
{
OwningGrid.OnColumnMaxWidthChanged(this, oldValue);
OwningGrid.NotifyColumnMaxWidthChanged(this, oldValue);
}
}
}
@@ -518,7 +518,7 @@ public abstract class DataGridColumn : AvaloniaObject
_minWidth = value;
if (OwningGrid != null)
{
OwningGrid.OnColumnMinWidthChanged(this, oldValue);
OwningGrid.NotifyColumnMinWidthChanged(this, oldValue);
}
}
}
@@ -979,7 +979,7 @@ public abstract class DataGridColumn : AvaloniaObject
SetWidthInternalNoCallback(newWidth);
if (newWidth != oldWidth)
{
OwningGrid.OnColumnWidthChanged(this);
OwningGrid.NotifyColumnWidthChanged(this);
}
}
@@ -577,10 +577,10 @@ public class DataGridColumnHeader : ContentControl
mousePositionHeaders = mousePositionHeaders.WithX(rightEdge - 1);
}
foreach (DataGridColumn column in OwningGrid.ColumnsInternal.GetDisplayedColumns())
foreach (var column in OwningGrid.ColumnsInternal.GetDisplayedColumns())
{
Point mousePosition = OwningGrid.ColumnHeaders!.Translate(column.HeaderCell!, mousePositionHeaders);
double columnMiddle = column.HeaderCell!.Bounds.Width / 2;
Point mousePosition = OwningGrid.ColumnHeaders!.Translate(column.HeaderCell, mousePositionHeaders);
double columnMiddle = column.HeaderCell.Bounds.Width / 2;
if (mousePosition.X >= 0 && mousePosition.X <= columnMiddle)
{
return column;
@@ -638,7 +638,7 @@ public class DataGridColumnHeader : ContentControl
// When we stop interacting with the column headers, we need to reset the drag mode
// and close any popups if they are open.
if (_dragColumn != null && _dragColumn.HeaderCell != null)
if (_dragColumn != null)
{
_dragColumn.HeaderCell.Cursor = _originalCursor;
}
@@ -773,13 +773,13 @@ public class DataGridColumnHeader : ContentControl
isVisible: true,
isFrozen: OwningColumn.IsFrozen,
isReadOnly: null);
targetPosition = targetColumn!.HeaderCell!.Translate(OwningGrid.ColumnHeaders, targetPosition);
targetPosition = targetColumn!.HeaderCell.Translate(OwningGrid.ColumnHeaders, targetPosition);
targetPosition = targetPosition.WithX(targetPosition.X + targetColumn.ActualWidth);
}
else
{
targetPosition = targetColumn.HeaderCell!.Translate(OwningGrid.ColumnHeaders, targetPosition);
targetPosition = targetColumn.HeaderCell.Translate(OwningGrid.ColumnHeaders, targetPosition);
}
OwningGrid.ColumnHeaders.DropLocationIndicatorOffset = targetPosition.X - scrollAmount;
@@ -139,7 +139,7 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
double dragIndicatorLeftEdge = 0;
double frozenLeftEdge = 0;
double scrollingLeftEdge = -OwningGrid.HorizontalOffset;
foreach (DataGridColumn dataGridColumn in OwningGrid.ColumnsInternal.GetVisibleColumns())
foreach (var dataGridColumn in OwningGrid.ColumnsInternal.GetVisibleColumns())
{
var columnHeader = dataGridColumn.HeaderCell;
Debug.Assert(columnHeader?.OwningColumn == dataGridColumn);
@@ -179,41 +179,39 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
var height = DragIndicator.Bounds.Height;
if (height <= 0)
{
height = DragIndicator.DesiredSize.Height;
}
DragIndicator.Arrange(new Rect(dragIndicatorLeftEdge, 0, DragIndicator.Bounds.Width, height));
}
if (DropLocationIndicator != null)
{
if (DropLocationIndicator is Control element)
{
EnsureColumnReorderingClip(element, finalSize.Height, frozenLeftEdge, DropLocationIndicatorOffset);
}
EnsureColumnReorderingClip(DropLocationIndicator, finalSize.Height, frozenLeftEdge, DropLocationIndicatorOffset);
DropLocationIndicator.Arrange(new Rect(DropLocationIndicatorOffset, 0,
DropLocationIndicator.Bounds.Width, DropLocationIndicator.Bounds.Height));
}
}
// Arrange filler
OwningGrid.OnFillerColumnWidthNeeded(finalSize.Width);
OwningGrid.NotifyFillerColumnWidthNeeded(finalSize.Width);
var fillerColumn = OwningGrid.ColumnsInternal.FillerColumn;
if (fillerColumn.FillerWidth > 0)
{
fillerColumn.HeaderCell!.IsVisible = true;
fillerColumn.HeaderCell.IsVisible = true;
fillerColumn.HeaderCell.Arrange(new Rect(scrollingLeftEdge, 0, fillerColumn.FillerWidth, finalSize.Height));
}
else
{
fillerColumn.HeaderCell!.IsVisible = false;
fillerColumn.HeaderCell.IsVisible = false;
}
// This needs to be updated after the filler column is configured
var lastVisibleColumn = OwningGrid.ColumnsInternal.LastVisibleColumn;
if (lastVisibleColumn != null)
{
lastVisibleColumn.HeaderCell!.UpdateSeparatorVisibility(lastVisibleColumn);
lastVisibleColumn.HeaderCell.UpdateSeparatorVisibility(lastVisibleColumn);
}
return finalSize;
@@ -309,8 +307,8 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
return default;
}
double height = OwningGrid.ColumnHeaderHeight;
bool autoSizeHeight;
var height = OwningGrid.ColumnHeaderHeight;
bool autoSizeHeight;
if (double.IsNaN(height))
{
// No explicit height values were set so we can autosize
@@ -322,14 +320,14 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
autoSizeHeight = false;
}
double totalDisplayWidth = 0;
var totalDisplayWidth = 0d;
OwningGrid.ColumnsInternal.EnsureVisibleEdgedColumnsWidth();
var lastVisibleColumn = OwningGrid.ColumnsInternal.LastVisibleColumn;
foreach (var column in OwningGrid.ColumnsInternal.GetVisibleColumns())
{
// Measure each column header
bool autoGrowWidth = column.Width.IsAuto || column.Width.IsSizeToHeader;
var columnHeader = column.HeaderCell!;
var autoGrowWidth = column.Width.IsAuto || column.Width.IsSizeToHeader;
var columnHeader = column.HeaderCell;
if (column != lastVisibleColumn)
{
columnHeader.UpdateSeparatorVisibility(lastVisibleColumn);
@@ -341,7 +339,7 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
{
// In the edge-case where we're given infinite width and we have star columns, the
// star columns grow to their predefined limit of 10,000 (or their MaxWidth)
double newDisplayWidth = column.Width.IsStar
var newDisplayWidth = column.Width.IsStar
? Math.Min(column.ActualMaxWidth, DataGrid.DefaultMaximumStarColumnWidth)
: Math.Max(column.ActualMinWidth, Math.Min(column.ActualMaxWidth, column.Width.DesiredValue));
column.SetWidthDisplayValue(newDisplayWidth);
@@ -380,11 +378,11 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
// Since we didn't know the final widths of the columns until we resized,
// we waited until now to measure each header
double leftEdge = 0;
var leftEdge = 0d;
foreach (DataGridColumn column in OwningGrid.ColumnsInternal.GetVisibleColumns())
{
column.ComputeLayoutRoundedWidth(leftEdge);
column.HeaderCell?.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
column.HeaderCell.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
if (autoSizeHeight)
{
height = Math.Max(height, column.HeaderCell!.DesiredSize.Height);
@@ -395,7 +393,7 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
}
// Add the filler column if it's not represented. We won't know whether we need it or not until Arrange
DataGridFillerColumn fillerColumn = OwningGrid.ColumnsInternal.FillerColumn;
var fillerColumn = OwningGrid.ColumnsInternal.FillerColumn;
if (!fillerColumn.IsRepresented)
{
Debug.Assert(!Children.Contains(fillerColumn.HeaderCell!));
@@ -406,7 +404,7 @@ public sealed class DataGridColumnHeadersPresenter : Panel, IChildIndexProvider
fillerColumn.HeaderCell.IsVisible = false;
}
fillerColumn.HeaderCell?.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
fillerColumn.HeaderCell.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
if (DragIndicator != null)
{
@@ -101,7 +101,7 @@ public partial class DataGrid
{
column.SetWidthInternalNoCallback(new DataGridLength(column.Width.Value, column.Width.UnitType,
desiredWidth, desiredWidth));
OnColumnWidthChanged(column);
NotifyColumnWidthChanged(column);
}
}
}
@@ -193,7 +193,7 @@ public partial class DataGrid
return amount;
}
internal void OnClearingColumns()
internal void NotifyClearingColumns()
{
// Rows need to be cleared first. There cannot be rows without also having columns.
ClearRows(false);
@@ -212,7 +212,7 @@ public partial class DataGrid
/// Invalidates the widths of all columns because the resizing behavior of an individual column has changed.
/// </summary>
/// <param name="column">Column with CanUserResize property that has changed.</param>
internal void OnColumnCanUserResizeChanged(DataGridColumn column)
internal void NotifyColumnCanUserResizeChanged(DataGridColumn column)
{
if (column.IsVisible)
{
@@ -241,7 +241,7 @@ public partial class DataGrid
if (columnsGrew && _autoGeneratingColumnOperationCount == 0 && ColumnsItemsInternal.Count == 1)
{
RefreshRows(false /*recycleRows*/, true /*clearRows*/);
RefreshRows(recycleRows:false, clearRows:true);
}
else
{
@@ -274,7 +274,7 @@ public partial class DataGrid
EnsureHorizontalLayout();
}
internal void OnColumnDisplayIndexChanging(DataGridColumn targetColumn, int newDisplayIndex)
internal void NotifyColumnDisplayIndexChanging(DataGridColumn targetColumn, int newDisplayIndex)
{
Debug.Assert(targetColumn != null);
Debug.Assert(newDisplayIndex != targetColumn.DisplayIndexWithFiller);
@@ -340,14 +340,14 @@ public partial class DataGrid
// Note that displayIndex of moved column is updated by caller.
}
internal void OnColumnBindingChanged(DataGridBoundColumn column)
internal void NotifyColumnBindingChanged(DataGridBoundColumn column)
{
// Update Binding in Displayed rows by regenerating the affected elements
if (_rowsPresenter != null)
{
foreach (DataGridRow row in GetAllRows())
foreach (var row in GetAllRows())
{
PopulateCellContent(false /*isCellEdited*/, column, row, row.Cells[column.Index]);
PopulateCellContent(isCellEdited:false, column, row, row.Cells[column.Index]);
}
}
}
@@ -357,7 +357,7 @@ public partial class DataGrid
/// </summary>
/// <param name="column">The column to adjust.</param>
/// <param name="oldValue">The old ActualMaxWidth of the column.</param>
internal void OnColumnMaxWidthChanged(DataGridColumn column, double oldValue)
internal void NotifyColumnMaxWidthChanged(DataGridColumn column, double oldValue)
{
Debug.Assert(column != null);
@@ -384,7 +384,7 @@ public partial class DataGrid
false);
}
OnColumnWidthChanged(column);
NotifyColumnWidthChanged(column);
}
}
@@ -393,7 +393,7 @@ public partial class DataGrid
/// </summary>
/// <param name="column">The column to adjust.</param>
/// <param name="oldValue">The old ActualMinWidth of the column.</param>
internal void OnColumnMinWidthChanged(DataGridColumn column, double oldValue)
internal void NotifyColumnMinWidthChanged(DataGridColumn column, double oldValue)
{
Debug.Assert(column != null);
@@ -420,26 +420,26 @@ public partial class DataGrid
false);
}
OnColumnWidthChanged(column);
NotifyColumnWidthChanged(column);
}
}
internal void OnColumnReadOnlyStateChanging(DataGridColumn dataGridColumn, bool isReadOnly)
internal void NotifyColumnReadOnlyStateChanging(DataGridColumn dataGridColumn, bool isReadOnly)
{
Debug.Assert(dataGridColumn != null);
if (isReadOnly && CurrentColumnIndex == dataGridColumn.Index)
{
// Edited column becomes read-only. Exit editing mode.
if (!EndCellEdit(DataGridEditAction.Commit, true /*exitEditingMode*/, ContainsFocus /*keepFocus*/,
true /*raiseEvents*/))
if (!EndCellEdit(DataGridEditAction.Commit, exitEditingMode:true, keepFocus:ContainsFocus,
raiseEvents:true))
{
EndCellEdit(DataGridEditAction.Cancel, true /*exitEditingMode*/, ContainsFocus /*keepFocus*/,
false /*raiseEvents*/);
EndCellEdit(DataGridEditAction.Cancel, exitEditingMode:true, keepFocus:ContainsFocus,
raiseEvents:false);
}
}
}
internal void OnColumnVisibleStateChanged(DataGridColumn updatedColumn)
internal void NotifyColumnVisibleStateChanged(DataGridColumn updatedColumn)
{
Debug.Assert(updatedColumn != null);
@@ -455,7 +455,7 @@ public partial class DataGrid
Debug.Assert(SelectedIndex == DataConnection!.IndexOf(SelectedItem));
if (SelectedIndex != -1)
{
SetAndSelectCurrentCell(updatedColumn.Index, SelectedIndex, true /*forceCurrentCellSelection*/);
SetAndSelectCurrentCell(updatedColumn.Index, SelectedIndex, forceCurrentCellSelection:true);
}
else
{
@@ -473,7 +473,7 @@ public partial class DataGrid
}
}
internal void OnColumnVisibleStateChanging(DataGridColumn targetColumn)
internal void NotifyColumnVisibleStateChanging(DataGridColumn targetColumn)
{
Debug.Assert(targetColumn != null);
@@ -498,7 +498,7 @@ public partial class DataGrid
}
}
internal void OnColumnWidthChanged(DataGridColumn updatedColumn)
internal void NotifyColumnWidthChanged(DataGridColumn updatedColumn)
{
Debug.Assert(updatedColumn != null);
if (updatedColumn.IsVisible)
@@ -507,7 +507,7 @@ public partial class DataGrid
}
}
internal void OnFillerColumnWidthNeeded(double finalWidth)
internal void NotifyFillerColumnWidthNeeded(double finalWidth)
{
var fillerColumn = ColumnsInternal.FillerColumn;
var totalColumnsWidth = ColumnsInternal.VisibleEdgedColumnsWidth;
@@ -530,7 +530,7 @@ public partial class DataGrid
Debug.Assert(CurrentColumnIndex == -1);
SetAndSelectCurrentCell(newCurrentCellCoordinates.ColumnIndex,
newCurrentCellCoordinates.Slot,
ColumnsInternal.VisibleColumnCount == 1 /*forceCurrentCellSelection*/);
forceCurrentCellSelection:ColumnsInternal.VisibleColumnCount == 1);
if (newDisplayIndex < FrozenColumnCountWithFiller)
{
@@ -539,7 +539,7 @@ public partial class DataGrid
}
}
internal void HandleInsertedColumnPreNotification(DataGridColumn insertedColumn)
internal void NotifyInsertedColumnPreNotification(DataGridColumn insertedColumn)
{
// Fix the Index of all following columns
CorrectColumnIndexesAfterInsertion(insertedColumn, 1);
@@ -557,7 +557,7 @@ public partial class DataGrid
{
var newColumnCount = ColumnsItemsInternal.Count;
foreach (DataGridRow row in GetAllRows())
foreach (var row in GetAllRows())
{
if (row.Cells.Count < newColumnCount)
{
@@ -577,7 +577,7 @@ public partial class DataGrid
}
}
internal DataGridCellCoordinates OnInsertingColumn(int columnIndexInserted, DataGridColumn insertColumn)
internal DataGridCellCoordinates NotifyInsertingColumn(int columnIndexInserted, DataGridColumn insertColumn)
{
DataGridCellCoordinates newCurrentCellCoordinates;
Debug.Assert(insertColumn != null);
@@ -725,7 +725,7 @@ public partial class DataGrid
// Underlying data of deleted column is gone. It cannot be accessed anymore.
// Do not end editing mode so that CellValidation doesn't get raised, since that event needs the current formatted value.
_temporarilyResetCurrentCell = true;
bool success = SetCurrentCellCore(-1, -1);
var success = SetCurrentCellCore(-1, -1);
Debug.Assert(success);
}
}
@@ -908,12 +908,12 @@ public partial class DataGrid
c => c.Width.IsStar && c.DisplayIndex >= displayIndex && c.IsVisible && c.Width.Value > 0 &&
(c.ActualCanUserResize || !userInitiated)))
{
int insertIndex = 0;
double distanceToTarget =
var insertIndex = 0;
var distanceToTarget =
Math.Min(column.ActualMaxWidth, Math.Max(targetWidth(column), column.ActualMinWidth)) -
column.Width.DisplayValue;
double factor = (increase ? Math.Max(0, distanceToTarget) : Math.Min(0, distanceToTarget)) /
column.Width.Value;
var factor = (increase ? Math.Max(0, distanceToTarget) : Math.Min(0, distanceToTarget)) /
column.Width.Value;
foreach (KeyValuePair<DataGridColumn, double> starColumnPair in starColumnPairs)
{
if (increase ? factor <= starColumnPair.Value : factor >= starColumnPair.Value)
@@ -995,10 +995,7 @@ public partial class DataGrid
DisplayData.FirstDisplayedScrollingCol = DisplayData.LastTotallyDisplayedScrollingCol = -1;
return invalidate;
}
else
{
firstDisplayedScrollingCol = dataGridColumn.Index;
}
firstDisplayedScrollingCol = dataGridColumn.Index;
}
cx -= _negHorizontalOffset;
@@ -1413,7 +1410,7 @@ public partial class DataGrid
Debug.Assert(index < ColumnsItemsInternal.Count);
Debug.Assert(ColumnsItemsInternal[index].IsVisible);
double x = 0;
var x = 0d;
foreach (var column in ColumnsInternal.GetVisibleColumns())
{
if (index == column.Index)
@@ -1693,10 +1690,7 @@ public partial class DataGrid
// no more column to display on the left of the first seen column
return;
}
else
{
newFirstVisibleScrollingCol = ColumnsItemsInternal[DisplayData.FirstDisplayedScrollingCol];
}
newFirstVisibleScrollingCol = ColumnsItemsInternal[DisplayData.FirstDisplayedScrollingCol];
}
}
@@ -1727,14 +1721,14 @@ public partial class DataGrid
{
return new DataGridCheckBoxColumn(ownerGrid);
}
else if (type == typeof(bool?))
if (type == typeof(bool?))
{
return new DataGridCheckBoxColumn(ownerGrid)
{
IsThreeState = true
};
}
return new DataGridTextColumn(ownerGrid);
}
+50 -50
View File
@@ -184,7 +184,7 @@ public partial class DataGrid
}
else
{
int currentlySelectedSlot = _selectedItems.GetIndexes().First();
var currentlySelectedSlot = _selectedItems.GetIndexes().First();
if (currentlySelectedSlot != slotException)
{
SelectionHasChanged = true;
@@ -274,8 +274,8 @@ public partial class DataGrid
// Row at that index needs to be displayed
if (isRow)
{
InsertElement(slot, GenerateRow(rowIndex, slot, item), false /*updateVerticalScrollBarOnly*/,
false /*isCollapsed*/, isRow);
InsertElement(slot, GenerateRow(rowIndex, slot, item), updateVerticalScrollBarOnly:false,
isCollapsed:false, isRow);
}
else
{
@@ -301,7 +301,7 @@ public partial class DataGrid
var item = DataConnection.GetDataItem(rowIndex);
// isCollapsed below is always false because we only use the method if we're not grouping
InsertElementAt(slot, rowIndex, item, null /*DataGridRowGroupInfo*/, false /*isCollapsed*/);
InsertElementAt(slot, rowIndex, item, groupInfo:null, isCollapsed:false);
}
internal bool IsColumnDisplayed(int columnIndex)
@@ -437,7 +437,7 @@ public partial class DataGrid
{
// First displayed row is partially scrolled of. Let's scroll it so that NegVerticalOffset becomes 0.
DisplayData.PendingVerticalScrollHeight = -NegVerticalOffset;
InvalidateRowsMeasure(false /*invalidateIndividualRows*/);
InvalidateRowsMeasure(invalidateIndividualElements:false);
}
return true;
@@ -569,7 +569,7 @@ public partial class DataGrid
}
// For now, all scenarios are for isSelected == true.
internal void SetRowsSelection(int startSlot, int endSlot /*, bool isSelected*/)
internal void SetRowsSelection(int startSlot, int endSlot)
{
Debug.Assert(startSlot >= 0 && startSlot < SlotCount);
Debug.Assert(endSlot >= 0 && endSlot < SlotCount);
@@ -578,7 +578,7 @@ public partial class DataGrid
_noSelectionChangeCount++;
try
{
if ( /*isSelected &&*/ !_selectedItems.ContainsAll(startSlot, endSlot))
if (!_selectedItems.ContainsAll(startSlot, endSlot))
{
// At least one row gets selected
SelectSlots(startSlot, endSlot, true);
@@ -971,9 +971,9 @@ public partial class DataGrid
}
// Figure out which slots actually need to be expanded since some might already be collapsed
double currentHeightChange = 0;
var firstSlot = startSlot;
var lastSlot = endSlot;
var currentHeightChange = 0d;
var firstSlot = startSlot;
var lastSlot = endSlot;
while (firstSlot <= endSlot)
{
firstSlot = _collapsedSlotsTable.GetNextIndex(firstSlot - 1);
@@ -1704,13 +1704,14 @@ public partial class DataGrid
// Additional row takes the spot of a displayed row - it is necessarily displayed
return true;
}
else if (DisplayData.FirstScrollingSlot == -1 &&
CellsEstimatedHeight > 0 &&
CellsWidth > 0)
if (DisplayData.FirstScrollingSlot == -1 &&
CellsEstimatedHeight > 0 &&
CellsWidth > 0)
{
return true;
}
else if (slot == GetNextVisibleSlot(DisplayData.LastScrollingSlot))
if (slot == GetNextVisibleSlot(DisplayData.LastScrollingSlot))
{
if (AvailableSlotElementRoom > 0)
{
@@ -2207,7 +2208,7 @@ public partial class DataGrid
lastDisplayedScrollingRow = 0;
}
int slot = lastDisplayedScrollingRow;
var slot = lastDisplayedScrollingRow;
while (MathUtilities.LessThan(deltaY, displayHeight) && slot >= 0)
{
deltaY += GetExactSlotElementHeight(slot);
@@ -2485,7 +2486,7 @@ public partial class DataGrid
collectionViewGroup.Items.CollectionChanged += HandleCollectionViewGroupCollectionChanged;
if (collectionViewGroup.Items[0] is DataGridCollectionViewGroup)
{
foreach (object subGroup in collectionViewGroup.Items)
foreach (var subGroup in collectionViewGroup.Items)
{
treeCount += CountAndPopulateGroupHeaders(subGroup, rootSlot + treeCount, level + 1);
}
@@ -2515,7 +2516,7 @@ public partial class DataGrid
ancestorGroupHeader.EnsureExpanderButtonIsChecked();
if (ancestorGroupHeader.Level > 0)
{
int slot = RowGroupHeadersTable.GetPreviousIndex(ancestorGroupHeader.RowGroupInfo!.Slot);
var slot = RowGroupHeadersTable.GetPreviousIndex(ancestorGroupHeader.RowGroupInfo!.Slot);
if (IsSlotVisible(slot))
{
ancestorGroupHeader = DisplayData.GetDisplayedElement(slot) as DataGridRowGroupHeader;
@@ -2530,11 +2531,11 @@ public partial class DataGrid
private void PopulateRowGroupHeadersTable()
{
if (DataConnection.CollectionView != null
&& DataConnection.CollectionView.CanGroup
&& DataConnection.CollectionView.Groups != null)
if (DataConnection.CollectionView != null &&
DataConnection.CollectionView.CanGroup &&
DataConnection.CollectionView.Groups != null)
{
int totalSlots = 0;
var totalSlots = 0;
_topLevelGroup = DataConnection.CollectionView.Groups;
_topLevelGroup.CollectionChanged += HandleCollectionViewGroupCollectionChanged;
foreach (var group in DataConnection.CollectionView.Groups)
@@ -2557,11 +2558,11 @@ public partial class DataGrid
{
// Initialize our array for the height of the RowGroupHeaders by Level.
// If the Length is the same, we can reuse the old array
int groupLevelCount = DataConnection.CollectionView.GroupingDepth;
var groupLevelCount = DataConnection.CollectionView.GroupingDepth;
if (_rowGroupHeightsByLevel == null || _rowGroupHeightsByLevel.Length != groupLevelCount)
{
_rowGroupHeightsByLevel = new double[groupLevelCount];
for (int i = 0; i < groupLevelCount; i++)
for (var i = 0; i < groupLevelCount; i++)
{
// Default height for now, the actual heights are updated as the RowGroupHeaders
// are added and measured
@@ -2572,8 +2573,8 @@ public partial class DataGrid
if (RowGroupSublevelIndents == null || RowGroupSublevelIndents.Length != groupLevelCount)
{
RowGroupSublevelIndents = new double[groupLevelCount];
double indent;
for (int i = 0; i < groupLevelCount; i++)
var indent = 0d;
for (var i = 0; i < groupLevelCount; i++)
{
indent = DefaultRowGroupSubLevelIndent;
RowGroupSublevelIndents[i] = indent;
@@ -2629,8 +2630,7 @@ public partial class DataGrid
{
if (IsSlotVisible(rowGroupInfo.Slot))
{
DataGridRowGroupHeader? rowGroupHeader =
DisplayData.GetDisplayedElement(rowGroupInfo.Slot) as DataGridRowGroupHeader;
var rowGroupHeader = DisplayData.GetDisplayedElement(rowGroupInfo.Slot) as DataGridRowGroupHeader;
Debug.Assert(rowGroupHeader != null);
rowGroupHeader.ToggleExpandCollapse(isVisible, setCurrent);
}
@@ -2646,7 +2646,7 @@ public partial class DataGrid
{
if (rowGroupInfo.Slot < DisplayData.FirstScrollingSlot)
{
double heightChange = UpdateRowGroupVisibility(rowGroupInfo, isVisible, isDisplayed: false);
var heightChange = UpdateRowGroupVisibility(rowGroupInfo, isVisible, isDisplayed: false);
// Use epsilon instead of 0 here so that in the off chance that our estimates put the vertical offset negative
// the user can still scroll to the top since the offset is non-zero
SetVerticalOffset(Math.Max(MathUtils.DoubleEpsilon, _verticalOffset + heightChange));
@@ -2665,7 +2665,7 @@ public partial class DataGrid
// Returns the inclusive count of expanded RowGroupHeaders from startSlot to endSlot
private int GetRowGroupHeaderCount(int startSlot, int endSlot, bool? isVisible, out double headersHeight)
{
int count = 0;
var count = 0;
headersHeight = 0;
foreach (var slot in RowGroupHeadersTable.GetIndexes(startSlot))
{
@@ -2674,7 +2674,7 @@ public partial class DataGrid
return count;
}
DataGridRowGroupInfo? rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
var rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (!isVisible.HasValue ||
(isVisible.Value && !_collapsedSlotsTable.Contains(slot)) ||
(!isVisible.Value && _collapsedSlotsTable.Contains(slot)))
@@ -2695,8 +2695,8 @@ public partial class DataGrid
bool isDisplayed)
{
double heightChange = 0;
int slotsExpanded = 0;
int startSlot = targetRowGroupInfo.Slot + 1;
var slotsExpanded = 0;
var startSlot = targetRowGroupInfo.Slot + 1;
int endSlot;
targetRowGroupInfo.IsVisible = newIsVisible;
@@ -2707,7 +2707,7 @@ public partial class DataGrid
{
if (slot >= startSlot)
{
DataGridRowGroupInfo? rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
var rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (rowGroupInfo != null)
{
if (rowGroupInfo.Level <= targetRowGroupInfo.Level)
@@ -2741,7 +2741,7 @@ public partial class DataGrid
{
// Collapse
endSlot = SlotCount - 1;
foreach (int slot in RowGroupHeadersTable.GetIndexes(targetRowGroupInfo.Slot + 1))
foreach (var slot in RowGroupHeadersTable.GetIndexes(targetRowGroupInfo.Slot + 1))
{
DataGridRowGroupInfo? rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
// TODO 这样处理合适吗?是跳过还是直接炸
@@ -2755,12 +2755,12 @@ public partial class DataGrid
}
}
int oldLastDisplayedSlot = DisplayData.LastScrollingSlot;
int endDisplayedSlot = Math.Min(endSlot, DisplayData.LastScrollingSlot);
var oldLastDisplayedSlot = DisplayData.LastScrollingSlot;
var endDisplayedSlot = Math.Min(endSlot, DisplayData.LastScrollingSlot);
if (isDisplayed)
{
// We need to remove all the displayed slots that aren't already collapsed
int elementsToRemove = endDisplayedSlot - startSlot + 1 -
var elementsToRemove = endDisplayedSlot - startSlot + 1 -
_collapsedSlotsTable.GetIndexCount(startSlot, endDisplayedSlot);
if (_focusedRow != null && _focusedRow.Slot >= startSlot && _focusedRow.Slot <= endSlot)
@@ -2770,7 +2770,7 @@ public partial class DataGrid
_focusedRow = null;
}
for (int i = 0; i < elementsToRemove; i++)
for (var i = 0; i < elementsToRemove; i++)
{
RemoveDisplayedElement(startSlot, wasDeleted: false, updateSlotInformation: false);
}
@@ -2780,7 +2780,7 @@ public partial class DataGrid
if (DisplayData.FirstScrollingSlot >= startSlot && DisplayData.FirstScrollingSlot <= endSlot)
{
// Our first visible slot was collapsed, find the replacement
int collapsedSlotsAbove = DisplayData.FirstScrollingSlot - startSlot -
var collapsedSlotsAbove = DisplayData.FirstScrollingSlot - startSlot -
_collapsedSlotsTable.GetIndexCount(startSlot, DisplayData.FirstScrollingSlot);
Debug.Assert(collapsedSlotsAbove > 0);
int newFirstScrollingSlot = GetNextVisibleSlot(DisplayData.FirstScrollingSlot);
@@ -2822,8 +2822,8 @@ public partial class DataGrid
// the distance to the last visible row and adjust the scrollbar if we collapsed more
if (isDisplayed && _verticalOffset > 0)
{
int lastVisibleSlot = GetPreviousVisibleSlot(SlotCount);
int slot = GetNextVisibleSlot(oldLastDisplayedSlot);
var lastVisibleSlot = GetPreviousVisibleSlot(SlotCount);
var slot = GetNextVisibleSlot(oldLastDisplayedSlot);
// AvailableSlotElementRoom ends up being the amount of the last slot that is partially scrolled off
// as a negative value, heightChangeBelowLastDisplayed slot is also a negative value since we're collapsing
double heightToLastVisibleSlot = AvailableSlotElementRoom + heightChangeBelowLastDisplayedSlot;
@@ -2835,7 +2835,7 @@ public partial class DataGrid
if (heightToLastVisibleSlot > heightChange)
{
double newVerticalOffset = _verticalOffset + heightChange - heightToLastVisibleSlot;
var newVerticalOffset = _verticalOffset + heightChange - heightToLastVisibleSlot;
if (newVerticalOffset > 0)
{
SetVerticalOffset(newVerticalOffset);
@@ -2846,7 +2846,7 @@ public partial class DataGrid
ResetDisplayedRows();
NegVerticalOffset = 0;
SetVerticalOffset(0);
int firstDisplayedRow = GetNextVisibleSlot(-1);
var firstDisplayedRow = GetNextVisibleSlot(-1);
UpdateDisplayedRows(firstDisplayedRow, CellsEstimatedHeight);
}
}
@@ -2864,7 +2864,7 @@ public partial class DataGrid
Debug.Assert(slot > -1);
Debug.Assert(rowGroupInfo != null);
DataGridRowGroupHeader groupHeader = DisplayData.GetUsedGroupHeader() ?? new DataGridRowGroupHeader();
var groupHeader = DisplayData.GetUsedGroupHeader() ?? new DataGridRowGroupHeader();
groupHeader.OwningGrid = this;
groupHeader.RowGroupInfo = rowGroupInfo;
groupHeader.DataContext = rowGroupInfo.CollectionViewGroup;
@@ -2910,9 +2910,9 @@ public partial class DataGrid
return new DataGridRowGroupInfo(null, true, -1, -1, -1);
}
foreach (int slot in RowGroupHeadersTable.GetIndexes())
foreach (var slot in RowGroupHeadersTable.GetIndexes())
{
DataGridRowGroupInfo? groupInfo = RowGroupHeadersTable.GetValueAt(slot);
var groupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (groupInfo!.CollectionViewGroup!.Items == collection)
{
return groupInfo;
@@ -2954,15 +2954,15 @@ public partial class DataGrid
var groupLevelCount = DataConnection.CollectionView.GroupingDepth;
Debug.Assert(groupHeader.Level >= 0 && groupHeader.Level < groupLevelCount);
double oldValue = RowGroupSublevelIndents[groupHeader.Level];
var oldValue = RowGroupSublevelIndents[groupHeader.Level];
if (groupHeader.Level > 0)
{
oldValue -= RowGroupSublevelIndents[groupHeader.Level - 1];
}
// Update the affected values in our table by the amount affected
double change = newValue - oldValue;
for (int i = groupHeader.Level; i < groupLevelCount; i++)
var change = newValue - oldValue;
for (var i = groupHeader.Level; i < groupLevelCount; i++)
{
RowGroupSublevelIndents[i] += change;
Debug.Assert(RowGroupSublevelIndents[i] >= 0);
@@ -2975,7 +2975,7 @@ public partial class DataGrid
{
foreach (var slot in RowGroupHeadersTable.GetIndexes())
{
DataGridRowGroupInfo? rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
var rowGroupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (rowGroupInfo?.CollectionViewGroup == collectionViewGroup)
{
return rowGroupInfo;
+8 -8
View File
@@ -741,7 +741,7 @@ public partial class DataGrid : TemplatedControl
ItemsSourceProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleItemsSourcePropertyChanged(e));
CanUserResizeColumnsProperty.Changed.AddClassHandler<DataGrid>((x, e) =>
x.HandleCanUserResizeColumnsChanged(e));
ColumnWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleColumnWidthChanged(e));
ColumnWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.NotifyColumnWidthChanged(e));
FrozenColumnCountProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleFrozenColumnCountChanged(e));
GridLinesVisibilityProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleGridLinesVisibilityChanged(e));
HeadersVisibilityProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleHeadersVisibilityChanged(e));
@@ -1121,7 +1121,7 @@ public partial class DataGrid : TemplatedControl
var oldValue = (double?)e.OldValue ?? double.NaN;
foreach (var column in ColumnsInternal.GetDisplayedColumns())
{
OnColumnMinWidthChanged(column, Math.Max(column.MinWidth, oldValue));
NotifyColumnMinWidthChanged(column, Math.Max(column.MinWidth, oldValue));
}
}
}
@@ -1131,9 +1131,9 @@ public partial class DataGrid : TemplatedControl
if (!_areHandlersSuspended)
{
var oldValue = (double?)e.OldValue ?? double.NaN;
foreach (DataGridColumn column in ColumnsInternal.GetDisplayedColumns())
foreach (var column in ColumnsInternal.GetDisplayedColumns())
{
OnColumnMaxWidthChanged(column, Math.Min(column.MaxWidth, oldValue));
NotifyColumnMaxWidthChanged(column, Math.Min(column.MaxWidth, oldValue));
}
}
}
@@ -1256,7 +1256,7 @@ public partial class DataGrid : TemplatedControl
InvalidateCellsArrange();
}
private void HandleColumnWidthChanged(AvaloniaPropertyChangedEventArgs e)
private void NotifyColumnWidthChanged(AvaloniaPropertyChangedEventArgs e)
{
var lengthValue = (DataGridLength?)e.NewValue;
if (lengthValue.HasValue)
@@ -2557,7 +2557,7 @@ public partial class DataGrid : TemplatedControl
return RowGroupHeadersTable.GetValueAt(slot)?.CollectionViewGroup;
}
rowIndex = RowIndexFromSlot(slot);
return DataConnection?.GetDataItem(rowIndex);
return DataConnection.GetDataItem(rowIndex);
}
internal bool ProcessDownKey(KeyEventArgs e)
@@ -3840,7 +3840,7 @@ public partial class DataGrid : TemplatedControl
if (invalidateIndividualElements)
{
foreach (Control element in _rowsPresenter.Children)
foreach (var element in _rowsPresenter.Children)
{
element.InvalidateMeasure();
}
@@ -4166,7 +4166,7 @@ public partial class DataGrid : TemplatedControl
if (_editingColumnIndex != -1 || (editAction == DataGridEditAction.Cancel && raiseEvents &&
!((DataConnection.EditableCollectionView != null &&
DataConnection.EditableCollectionView.CanCancelEdit) ||
(EditingRow.DataContext is IEditableObject))))
EditingRow.DataContext is IEditableObject)))
{
// Ending the row edit will fail immediately under the following conditions:
// 1. We haven't ended the cell edit yet.
@@ -307,7 +307,7 @@ internal class DataGridDataConnection
var enumerator = enumerable.GetEnumerator();
try
{
int i = -1;
var i = -1;
while (enumerator.MoveNext() && i < index)
{
i++;
@@ -336,9 +336,9 @@ internal class DataGridDataConnection
{
if (!string.IsNullOrEmpty(propertyName))
{
Type propertyType = DataType;
var propertyType = DataType;
PropertyInfo? propertyInfo = null;
List<string> propertyNames = TypeHelper.SplitPropertyPath(propertyName);
var propertyNames = TypeHelper.SplitPropertyPath(propertyName);
for (var i = 0; i < propertyNames.Count; i++)
{
propertyInfo = propertyType.GetPropertyOrIndexer(propertyNames[i], out _);
@@ -8,7 +8,7 @@ internal class DataGridDisplayData
{
private Stack<DataGridRow> _fullyRecycledRows; // list of Rows that have been fully recycled (Collapsed)
private int _headScrollingElements; // index of the row in _scrollingRows that is the first displayed row
private DataGrid _owner;
private DataGrid _ownerGrid;
// list of Rows which have not been fully recycled (avoids Measure in several cases)
private Stack<DataGridRow> _recyclableRows;
@@ -24,7 +24,7 @@ internal class DataGridDisplayData
public DataGridDisplayData(DataGrid owner)
{
_owner = owner;
_ownerGrid = owner;
ResetSlotIndexes();
FirstDisplayedScrollingCol = -1;
@@ -87,7 +87,7 @@ internal class DataGridDisplayData
ResetSlotIndexes();
if (recycle)
{
foreach (Control element in _scrollingElements)
foreach (var element in _scrollingElements)
{
if (element is DataGridRow row)
{
@@ -126,9 +126,9 @@ internal class DataGridDisplayData
LastScrollingSlot--;
}
}
else if (_owner.IsSlotVisible(slot))
else if (_ownerGrid.IsSlotVisible(slot))
{
UnloadScrollingElement(slot, true /*updateSlotInformation*/, true /*wasDeleted*/);
UnloadScrollingElement(slot, updateSlotInformation:true, wasDeleted:true);
}
// This cannot be an else condition because if there are 2 rows left, and you delete the first one
@@ -152,18 +152,18 @@ internal class DataGridDisplayData
{
LastScrollingSlot++;
}
else if (_owner.GetPreviousVisibleSlot(slot) <= LastScrollingSlot || LastScrollingSlot == -1)
else if (_ownerGrid.GetPreviousVisibleSlot(slot) <= LastScrollingSlot || LastScrollingSlot == -1)
{
Debug.Assert(element != null);
// The row was inserted in our viewport, add it as a scrolling row
LoadScrollingSlot(slot, element, true /*updateSlotInformation*/);
LoadScrollingSlot(slot, element, updateSlotInformation:true);
}
}
private int GetCircularListIndex(int slot, bool wrap)
{
int index = slot - FirstScrollingSlot - _headScrollingElements -
_owner.GetCollapsedSlotCount(FirstScrollingSlot, slot);
_ownerGrid.GetCollapsedSlotCount(FirstScrollingSlot, slot);
return wrap ? index % _scrollingElements.Count : index;
}
@@ -195,12 +195,12 @@ internal class DataGridDisplayData
Debug.Assert(slot >= FirstScrollingSlot);
Debug.Assert(slot <= LastScrollingSlot);
return _scrollingElements[GetCircularListIndex(slot, true /*wrap*/)];
return _scrollingElements[GetCircularListIndex(slot, wrap:true)];
}
internal DataGridRow? GetDisplayedRow(int rowIndex)
{
return GetDisplayedElement(_owner.SlotFromRowIndex(rowIndex)) as DataGridRow;
return GetDisplayedElement(_ownerGrid.SlotFromRowIndex(rowIndex)) as DataGridRow;
}
internal IEnumerable<Control> GetScrollingElements(Predicate<object>? filter = null)
@@ -250,8 +250,8 @@ internal class DataGridDisplayData
else
{
// The slot should be adjacent to the other slots being displayed
Debug.Assert(slot >= _owner.GetPreviousVisibleSlot(FirstScrollingSlot) &&
slot <= _owner.GetNextVisibleSlot(LastScrollingSlot));
Debug.Assert(slot >= _ownerGrid.GetPreviousVisibleSlot(FirstScrollingSlot) &&
slot <= _ownerGrid.GetNextVisibleSlot(LastScrollingSlot));
if (updateSlotInformation)
{
if (slot < FirstScrollingSlot)
@@ -260,11 +260,11 @@ internal class DataGridDisplayData
}
else
{
LastScrollingSlot = _owner.GetNextVisibleSlot(LastScrollingSlot);
LastScrollingSlot = _ownerGrid.GetNextVisibleSlot(LastScrollingSlot);
}
}
int insertIndex = GetCircularListIndex(slot, false /*wrap*/);
var insertIndex = GetCircularListIndex(slot, wrap:false);
if (insertIndex > _scrollingElements.Count)
{
// We need to wrap around from the bottom to the top of our circular list; as a result the head of the list moves forward
@@ -292,8 +292,8 @@ internal class DataGridDisplayData
// Stops tracking the element at the given slot as a scrolling element
internal void UnloadScrollingElement(int slot, bool updateSlotInformation, bool wasDeleted)
{
Debug.Assert(_owner.IsSlotVisible(slot));
var elementIndex = GetCircularListIndex(slot, false /*wrap*/);
Debug.Assert(_ownerGrid.IsSlotVisible(slot));
var elementIndex = GetCircularListIndex(slot, wrap:false);
if (elementIndex > _scrollingElements.Count)
{
// We need to wrap around from the top to the bottom of our circular list
@@ -307,11 +307,11 @@ internal class DataGridDisplayData
{
if (slot == FirstScrollingSlot && !wasDeleted)
{
FirstScrollingSlot = _owner.GetNextVisibleSlot(FirstScrollingSlot);
FirstScrollingSlot = _ownerGrid.GetNextVisibleSlot(FirstScrollingSlot);
}
else
{
LastScrollingSlot = _owner.GetPreviousVisibleSlot(LastScrollingSlot);
LastScrollingSlot = _ownerGrid.GetPreviousVisibleSlot(LastScrollingSlot);
}
if (LastScrollingSlot < FirstScrollingSlot)
@@ -63,7 +63,7 @@ public sealed class DataGridRowsPresenter : Panel, IChildIndexProvider
return base.ArrangeOverride(finalSize);
}
OwningGrid.OnFillerColumnWidthNeeded(finalSize.Width);
OwningGrid.NotifyFillerColumnWidthNeeded(finalSize.Width);
var rowDesiredWidth = OwningGrid.RowHeadersDesiredWidth +
OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth +
@@ -24,7 +24,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
{
get
{
int indexCount = 0;
var indexCount = 0;
foreach (Range<T> range in _list)
{
indexCount += range.Count;
@@ -650,7 +650,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
else
{
var lowerRangeIndex = startRangeIndex ?? FindRangeIndex(startIndex);
var lowerRange = (lowerRangeIndex < 0) ? null : _list[lowerRangeIndex];
var lowerRange = lowerRangeIndex < 0 ? null : _list[lowerRangeIndex];
if (lowerRange == null)
{
if (lowerRangeIndex < 0)
@@ -746,7 +746,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
if (front == end)
{
range = _list[front];
if (range.ContainsIndex(index) || (range.UpperBound < index))
if (range.ContainsIndex(index) || range.UpperBound < index)
{
// we found it or the index isn't there and we're one range before
return front;