I'm trying to retrieve a list of columns in a DataGrid that have a particular background color/brush, using the following:
Dim OutputCols As New List(Of DataGridColumn)
OutputCols = datagrid_Output.Columns.Where(Function(a) Not (a.CellStyle Is Nothing) AndAlso a.GetValue(BackgroundProperty) Is GridOutputsColor).ToList
However, this doesn't work and I discovered that GetValue(BackgroundProperty) is returning blank value. If I do this, however, I get the SetterBase object, instead of the Setter(s) that I want:
Dim OutputCols As New List(Of DataGridColumn)
OutputCols = datagrid_Output.Columns.Where(Function(a) Not (a.CellStyle Is Nothing) AndAlso a.CellStyle.Setters.First(Function(b) b.property Is BackgroundProperty).value Is GridOutputsColor).ToList
...and it doesn't work because Function(b) returns the SetterBase object instead of each Setter.
Found the nasty solution:
Dim OutputCols As New List(Of DataGridColumn)
OutputCols = datagrid_Output.Columns.Where(Function(a) Not (a.CellStyle Is Nothing) AndAlso TryCast(a.CellStyle.Setters.Where(Function(b) TryCast(b, Setter).Property Is BackgroundProperty).ToList.First, Setter).Value Is GridOutputsColor).ToList