Hi,
I am trying to conditionally format the contents of merged cells. For this I have implemented a MergedCellStyleSelector as per the examples. The setters all work as expected except for setting the foreground color. If I look at the live visual tree in VS I can see that the data gets presented in a text block which does not inherit from the foreground property set on the conditional style.
public
class
MergedSlotStyleSelector : StyleSelector
{
public
override
Style SelectStyle(
object
item, DependencyObject container)
{
var info = item
as
MergedCellInfo;
var cell = container
as
GridViewMergedCell;
var column = cell.DataColumn;
var ctx = cell.DataContext
as
MainViewModel;
var vm = ctx.SectionElements.OrderBy(o=>o.Sequence).ToArray()[info.VerticalStart];
var baseStyle = Application.Current.Resources[
"GridViewMergedCellStyle"
]
as
Style;
var background =
new
SolidColorBrush(Telerik.Windows.Controls.FluentPalette.Palette.AccentColor);
var foreground =
new
SolidColorBrush(Telerik.Windows.Controls.FluentPalette.Palette.PrimaryMouseOverColor);
var style =
new
Style(
typeof
(GridViewMergedCell), baseStyle);
style.Setters.Add(
new
Setter(GridViewMergedCell.VerticalContentAlignmentProperty, VerticalAlignment.Center));
style.Setters.Add(
new
Setter(GridViewMergedCell.HorizontalContentAlignmentProperty, HorizontalAlignment.Right));
if
(vm.IsRulingSegment)
{
style.Setters.Add(
new
Setter(GridViewMergedCell.BackgroundProperty, background));
//<-- THIS WORKS
style.Setters.Add(
new
Setter(GridViewMergedCell.ForegroundProperty, foreground));
//<-- THIS DOES NOT WORK
style.Setters.Add(
new
Setter(GridViewMergedCell.FontWeightProperty, FontWeights.Bold));
//<-- THIS WORKS
}
return
style;
}
}