I've got the following GridViewDataColumn:
The OldestBalanceStyleSelector is as follows:
I need to add a ToolTip that describes what the color means. Typically, I'd do something like this in XAML:
However, this isn't showing correctly. Am I doing the ContentPresenter part wrong? Can this be accomplished in the CellStyleSelector at the same time I'm setting the color of the background? This would be ideal, as I wouldn't need a converter or anything, I'd just set the text statically within that switch statement.
1.
<
telerik:GridViewDataColumn
2.
Header
=
"Oldest
Balance"
3.
DataMemberBinding
=
"{Binding OldestBalance, Converter={StaticResource Currency2Converter}}"
4.
CellStyleSelector
=
"{StaticResource OldestBalanceColorStyleSelector}"
5.
HeaderCellStyle
=
"{StaticResource rgvHeaderCellStyle}"
6.
HeaderTextAlignment
=
"Center"
7.
TextAlignment
=
"Right"
8.
Width
=
"Auto"
/>
The OldestBalanceStyleSelector is as follows:
01.
public
class
OldestBalanceColorStyleSelector : Telerik.Windows.Controls.StyleSelector
02.
{
03.
public
override
Style SelectStyle(
object
item, DependencyObject container)
04.
{
05.
var cpData = item
as
CreditPolicyData;
06.
var cell = container
as
GridViewCell;
07.
var style =
new
Style(
typeof
(GridViewCell));
08.
09.
style.Setters.Add(
new
Setter
10.
(
11.
GridViewCell.BorderBrushProperty,
12.
new
SolidColorBrush(Colors.Transparent)
13.
));
14.
style.Setters.Add(
new
Setter
15.
(
16.
GridViewCell.BorderThicknessProperty,
17.
new
Thickness(0)
18.
));
19.
style.Setters.Add(
new
Setter
20.
(
21.
GridViewCell.MarginProperty,
22.
new
Thickness(0)
23.
));
24.
style.Setters.Add(
new
Setter
25.
(
26.
GridViewCell.PaddingProperty,
27.
new
Thickness(20, 10, 20, 10)
28.
));
29.
30.
if
31.
(
32.
cpData.IsNotNull() &&
33.
cpData.OldestBalanceColor.IsNotNullOrEmpty()
34.
)
35.
{
36.
switch
(cpData.OldestBalanceColor.ToLower())
37.
{
38.
case
"red"
:
39.
style.Setters.Add(
new
Setter
40.
(
41.
GridViewCell.BackgroundProperty,
42.
new
SolidColorBrush(Color.FromArgb(255, 214, 50, 50))
43.
));
44.
style.Setters.Add(
new
Setter
45.
(
46.
GridViewCell.ForegroundProperty,
47.
new
SolidColorBrush(Colors.White)
48.
));
49.
break
;
50.
51.
case
"yellow"
:
52.
style.Setters.Add(
new
Setter
53.
(
54.
GridViewCell.BackgroundProperty,
55.
new
SolidColorBrush(Color.FromArgb(255, 255, 238, 98))
56.
));
57.
style.Setters.Add(
new
Setter
58.
(
59.
GridViewCell.ForegroundProperty,
60.
new
SolidColorBrush(Colors.Black)
61.
));
62.
break
;
63.
64.
case
"black"
:
65.
style.Setters.Add(
new
Setter
66.
(
67.
GridViewCell.BackgroundProperty,
68.
new
SolidColorBrush(Color.FromArgb(255, 34, 40, 43))
69.
));
70.
style.Setters.Add(
new
Setter
71.
(
72.
GridViewCell.ForegroundProperty,
73.
new
SolidColorBrush(Colors.White)
74.
));
75.
break
;
76.
77.
default
:
78.
style.Setters.Add(
new
Setter
79.
(
80.
GridViewCell.BackgroundProperty,
81.
new
SolidColorBrush(Colors.Transparent)
82.
));
83.
break
;
84.
}
85.
}
86.
else
87.
{
88.
style.Setters.Add(
new
Setter
89.
(
90.
GridViewCell.BackgroundProperty,
91.
new
SolidColorBrush(Colors.Transparent)
92.
));
93.
}
94.
95.
return
style;
96.
}
97.
}
I need to add a ToolTip that describes what the color means. Typically, I'd do something like this in XAML:
01.
<telerik:GridViewColumn.CellStyle>
02.
<Style
03.
BasedOn=
"{StaticResource rgvCellStyle}"
04.
TargetType=
"telerik:GridViewCell"
>
05.
06.
<Setter Property=
"Template"
>
07.
<Setter.Value>
08.
<ControlTemplate TargetType=
"telerik:GridViewCell"
>
09.
10.
<Border
11.
Background=
"{TemplateBinding Background}"
12.
BorderBrush=
"{TemplateBinding BorderBrush}"
13.
BorderThickness=
"{TemplateBinding BorderThickness}"
14.
ToolTipService.Placement=
"Bottom"
15.
ToolTipService.ToolTip=
"{Binding OldestBalanceColorText}"
>
16.
17.
<ContentPresenter />
18.
19.
</Border>
20.
21.
</ControlTemplate>
22.
</Setter.Value>
23.
</Setter>
24.
25.
</Style>
26.
</telerik:GridViewColumn.CellStyle>
However, this isn't showing correctly. Am I doing the ContentPresenter part wrong? Can this be accomplished in the CellStyleSelector at the same time I'm setting the color of the background? This would be ideal, as I wouldn't need a converter or anything, I'd just set the text statically within that switch statement.