diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridRow.cs b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridRow.cs index 86840408c42..c721cf7efad 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridRow.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridRow.cs @@ -1122,40 +1122,11 @@ internal void EnsureForeground() { DiagnosticsDebug.Assert(this.Index != -1, "Expected Index other than -1."); - PropertyMetadata metadataInfo = DataGridRow.ForegroundProperty.GetMetadata(typeof(DataGridRow)); - Brush defaultForeground = metadataInfo == null ? null : metadataInfo.DefaultValue as Brush; - Brush newForeground = null; + var newForeground = this.Index % 2 == 0 || this.OwningGrid.AlternatingRowForeground == null + ? this.OwningGrid.RowForeground + : this.OwningGrid.AlternatingRowForeground; - if (this.Foreground.Equals(defaultForeground)) - { - if (this.Index % 2 == 0 || this.OwningGrid.AlternatingRowForeground == null) - { - // Use OwningGrid.RowForeground if the index is even or if the OwningGrid.AlternatingRowForeground is null - if (this.OwningGrid.RowForeground != null) - { - newForeground = this.OwningGrid.RowForeground; - } - } - else - { - // Alternate row - if (this.OwningGrid.AlternatingRowForeground != null) - { - newForeground = this.OwningGrid.AlternatingRowForeground; - } - } - - if (newForeground == null) - { - newForeground = this.Foreground; - } - } - else - { - newForeground = this.Foreground; - } - - this.ComputedForeground = newForeground; + this.ComputedForeground = newForeground ?? this.Foreground; } else {