I've followed your help sample and created a custom style selector like this:-
I have also created the necessary styles in my view XAML:-
The problem is, I'm programmatically creating the RadGridView columns in my view model. I can't simply assign an instance of my custom style selector to the column's CellStyleSelector property as there is nothing linking that instance to the styles in the XAML. Am I going about this the wrong way?
public
class
BlockTypeStyleSelector : StyleSelector
{
public
override
Style SelectStyle(
object
item, DependencyObject container)
{
if
(item
is
SampleRun)
{
var sampleRun = item
as
SampleRun;
switch
(sampleRun.BlockType)
{
case
BlockType.NormalBlock:
return
NormalBlockStyle;
case
BlockType.CalibrationBlock:
return
CalibrationBlockStyle;
}
}
return
null
;
}
public
Style NormalBlockStyle {
get
;
set
; }
public
Style CalibrationBlockStyle {
get
;
set
; }
}
I have also created the necessary styles in my view XAML:-
<
GridStyleSelectors:BlockTypeStyleSelector
x:Key
=
"blockTypeStyle"
>
<
GridStyleSelectors:BlockTypeStyleSelector.NormalBlockStyle
>
<
Style
TargetType
=
"telerik:GridViewCell"
>
<
Setter
Property
=
"Background"
Value
=
"White"
/>
</
Style
>
</
GridStyleSelectors:BlockTypeStyleSelector.NormalBlockStyle
>
<
GridStyleSelectors:BlockTypeStyleSelector.CalibrationBlockStyle
>
<
Style
TargetType
=
"telerik:GridViewCell"
>
<
Setter
Property
=
"Background"
Value
=
"PaleGoldenrod"
/>
</
Style
>
</
GridStyleSelectors:BlockTypeStyleSelector.CalibrationBlockStyle
>
</
GridStyleSelectors:BlockTypeStyleSelector
>
The problem is, I'm programmatically creating the RadGridView columns in my view model. I can't simply assign an instance of my custom style selector to the column's CellStyleSelector property as there is nothing linking that instance to the styles in the XAML. Am I going about this the wrong way?