Skip to content

Commit 74b7c12

Browse files
committed
Small refactor on DataGrid.
1 parent 919df39 commit 74b7c12

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridCellsPresenter.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ protected override Size MeasureOverride(Size availableSize)
246246
{
247247
cell.Measure(new Size(column.ActualMaxWidth, measureHeight));
248248
this.OwningGrid.AutoSizeColumn(column, cell.DesiredSize.Width);
249-
column.ComputeLayoutRoundedWidth(totalDisplayWidth, GetScale());
249+
column.ComputeLayoutRoundedWidth(totalDisplayWidth);
250250
}
251251
else if (!this.OwningGrid.UsesStarSizing)
252252
{
253-
column.ComputeLayoutRoundedWidth(scrollingLeftEdge, GetScale());
253+
column.ComputeLayoutRoundedWidth(scrollingLeftEdge);
254254
cell.Measure(new Size(column.LayoutRoundedWidth, measureHeight));
255255
}
256256

@@ -283,7 +283,7 @@ protected override Size MeasureOverride(Size availableSize)
283283
foreach (DataGridColumn column in this.OwningGrid.ColumnsInternal.GetVisibleColumns())
284284
{
285285
DataGridCell cell = this.OwningRow.Cells[column.Index];
286-
column.ComputeLayoutRoundedWidth(leftEdge, GetScale());
286+
column.ComputeLayoutRoundedWidth(leftEdge);
287287
cell.Measure(new Size(column.LayoutRoundedWidth, measureHeight));
288288
if (autoSizeHeight)
289289
{
@@ -302,18 +302,6 @@ protected override Size MeasureOverride(Size availableSize)
302302
return new Size(this.OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth, this.DesiredHeight);
303303
}
304304

305-
private double GetScale()
306-
{
307-
if (OwningGrid.XamlRoot != null)
308-
{
309-
return OwningGrid.XamlRoot.RasterizationScale;
310-
}
311-
else
312-
{
313-
return Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
314-
}
315-
}
316-
317305
internal void Recycle()
318306
{
319307
// Clear out the cached desired height so it is not reused for other rows

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridColumn.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,20 @@ internal DataGridLength CoerceWidth(DataGridLength width)
10551055
/// rounding process, so we need to do it ourselves. If we don't, then we'll end up with some
10561056
/// pixel gaps and/or overlaps between columns.
10571057
/// </summary>
1058-
internal void ComputeLayoutRoundedWidth(double leftEdge, double scale)
1058+
internal void ComputeLayoutRoundedWidth(double leftEdge)
10591059
{
10601060
if (this.OwningGrid != null && this.OwningGrid.UseLayoutRounding)
10611061
{
1062+
double scale;
1063+
if (OwningGrid.XamlRoot != null)
1064+
{
1065+
scale = OwningGrid.XamlRoot.RasterizationScale;
1066+
}
1067+
else
1068+
{
1069+
scale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
1070+
}
1071+
10621072
double roundedLeftEdge = Math.Floor((scale * leftEdge) + 0.5) / scale;
10631073
double roundedRightEdge = Math.Floor((scale * (leftEdge + this.ActualWidth)) + 0.5) / scale;
10641074
this.LayoutRoundedWidth = roundedRightEdge - roundedLeftEdge;

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridColumnHeadersPresenter.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ protected override Size MeasureOverride(Size availableSize)
338338
{
339339
columnHeader.Measure(new Size(column.ActualMaxWidth, double.PositiveInfinity));
340340
this.OwningGrid.AutoSizeColumn(column, columnHeader.DesiredSize.Width);
341-
column.ComputeLayoutRoundedWidth(totalDisplayWidth, GetScale());
341+
column.ComputeLayoutRoundedWidth(totalDisplayWidth);
342342
}
343343
else if (!this.OwningGrid.UsesStarSizing)
344344
{
345-
column.ComputeLayoutRoundedWidth(totalDisplayWidth, GetScale());
345+
column.ComputeLayoutRoundedWidth(totalDisplayWidth);
346346
columnHeader.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
347347
}
348348

@@ -367,7 +367,7 @@ protected override Size MeasureOverride(Size availableSize)
367367
double leftEdge = 0;
368368
foreach (var column in this.OwningGrid.ColumnsInternal.GetVisibleColumns())
369369
{
370-
column.ComputeLayoutRoundedWidth(leftEdge, GetScale());
370+
column.ComputeLayoutRoundedWidth(leftEdge);
371371
column.HeaderCell.Measure(new Size(column.LayoutRoundedWidth, double.PositiveInfinity));
372372
if (autoSizeHeight)
373373
{
@@ -407,18 +407,6 @@ protected override Size MeasureOverride(Size availableSize)
407407
return new Size(this.OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth, height);
408408
}
409409

410-
private double GetScale()
411-
{
412-
if (OwningGrid.XamlRoot != null)
413-
{
414-
return OwningGrid.XamlRoot.RasterizationScale;
415-
}
416-
else
417-
{
418-
return Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
419-
}
420-
}
421-
422410
/// <summary>
423411
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
424412
/// </summary>

0 commit comments

Comments
 (0)