I am populating a griviews columns from the ViewModel and would now like to reference a complex CellStyleSelector. This is normally reference in XAML using...
<
sel:EventDashboardSelector
x:Key
=
"eventDashboardSelector"
NormalStyle
=
"{StaticResource NormalCellStyle}"
CompletedStyle
=
"{StaticResource CompletedStyle}"
OverdueStyle
=
"{StaticResource OverdueStyle}"
DueStyle
=
"{StaticResource DueStyle}"
PendingStyle
=
"{StaticResource PendingStyle}"
/>
The style selector class is in ..Code.StyleSelectors.EventdashboardSelector.cs
This is the MVVM snippet where I create the columns
foreach
(DateTime oDate
in
lDates)
{
sUniqueName =
string
.Format(
"Event{0}"
, i);
oCol =
new
GridViewDataColumn();
oCol.HeaderCellStyle = HeaderStyle();
if
(oDate == DateTime.Today)
{
oCol.HeaderCellStyle = HeaderStyleRed();
}
oCol.CellStyleSelector = vwDashboard.Resources[
"eventDashboardSelector"
]
as
StyleSelector; <<<<----This
is
my attempt to reference the resource
oCol.Width = 40;
oCol.Header =
string
.Format(
"{0}/{1}"
, oDate.Day, oDate.Month);
oCol.UniqueName = sUniqueName;
oCol.DataMemberBinding =
new
System.Windows.Data.Binding(sUniqueName);
oCol.HeaderTextAlignment = TextAlignment.Center;
oCol.TextAlignment = TextAlignment.Center;
ColumnList.Add(oCol);
i++;
}
Your help will be appreciated.