如何通过代码创建ComponentResourceKey?

时间:2012-07-10 11:49:13

标签: c# .net wpf xaml

如何通过代码后面的代码编写下面的代码。

<Style x:Key="{ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}">
    <Setter Property="TextBlock.Foreground" Value="#FF333333" />
</Style>

这就是我的意思。

void ApplyRecordAreaStyle()
{
    Style recordstyle = new Style(typeof(DataRecordCellArea));

    recordstyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundAlternateProperty, SelectedBackground));
    recordstyle.Setters.Add(new Setter(DataRecordCellArea.ForegroundAlternateStyleProperty, ????????));

    xamGrid.FieldLayoutSettings.DataRecordCellAreaStyle = recordstyle;
}

1 个答案:

答案 0 :(得分:0)

替代属性的值是画笔。

例如:

recordstyle.Setters.Add(new Setter(DataRecordCellArea.ForegroundAlternateStyleProperty, Brushes.Red));

任何画笔都可以。您不仅可以使用如我的示例中所示的实心画笔,还可以使用渐变画笔。