Skip to content

Commit 3e64e67

Browse files
committed
Revert "Fixes AlternatingRowForeground not being applied"
This reverts commit 53bc957.
1 parent 53bc957 commit 3e64e67

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,11 +1122,40 @@ internal void EnsureForeground()
11221122
{
11231123
DiagnosticsDebug.Assert(this.Index != -1, "Expected Index other than -1.");
11241124

1125-
var newForeground = this.Index % 2 == 0 || this.OwningGrid.AlternatingRowForeground == null
1126-
? this.OwningGrid.RowForeground
1127-
: this.OwningGrid.AlternatingRowForeground;
1125+
PropertyMetadata metadataInfo = DataGridRow.ForegroundProperty.GetMetadata(typeof(DataGridRow));
1126+
Brush defaultForeground = metadataInfo == null ? null : metadataInfo.DefaultValue as Brush;
1127+
Brush newForeground = null;
11281128

1129-
this.ComputedForeground = newForeground ?? this.Foreground;
1129+
if (this.Foreground.Equals(defaultForeground))
1130+
{
1131+
if (this.Index % 2 == 0 || this.OwningGrid.AlternatingRowForeground == null)
1132+
{
1133+
// Use OwningGrid.RowForeground if the index is even or if the OwningGrid.AlternatingRowForeground is null
1134+
if (this.OwningGrid.RowForeground != null)
1135+
{
1136+
newForeground = this.OwningGrid.RowForeground;
1137+
}
1138+
}
1139+
else
1140+
{
1141+
// Alternate row
1142+
if (this.OwningGrid.AlternatingRowForeground != null)
1143+
{
1144+
newForeground = this.OwningGrid.AlternatingRowForeground;
1145+
}
1146+
}
1147+
1148+
if (newForeground == null)
1149+
{
1150+
newForeground = this.Foreground;
1151+
}
1152+
}
1153+
else
1154+
{
1155+
newForeground = this.Foreground;
1156+
}
1157+
1158+
this.ComputedForeground = newForeground;
11301159
}
11311160
else
11321161
{
@@ -1502,4 +1531,4 @@ public int Debug_Index
15021531
}
15031532
#endif
15041533
}
1505-
}
1534+
}

0 commit comments

Comments
 (0)