我有一個畫筆定義爲代碼中的常量,我想將其添加到使用特定鍵在XAML中定義的DataGrid的資源標記中。將常量添加到資源
我該怎麼做?
我需要用,因爲林覆蓋高亮行的外觀的鍵添加現有刷:
<DataGrid.Resources>
<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FFD6A4" Offset="0"/>
<GradientStop Color="#FFAB3F" Offset="1"/>
</LinearGradientBrush>
</DataGrid.Resources>
我想不必重新定義它使用的畫筆是:
public static class Colours
{
public static LinearGradientBrush HighlightedRow { get; private set; }
static Colours()
{
HighlightedRow = new LinearGradientBrush(Color.FromRgb(255, 214, 164), Color.FromRgb(255, 171, 63), 90);
}
}
請寫下您的代碼,以便我可以看到您想實現的目標。也許一個可能的解決方案是DataBinding到Viewmodel –
爲什麼你想把它放在你的資源?你能不能只綁定它? –
沒有要綁定的HighlightBrush屬性,因此該關鍵需要在DataGrid的資源中覆蓋 –