Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:58:45+00:00 2026-05-15T09:58:45+00:00

This is quite obscure, I may just be missing something extremely simple. Scenario 1

  • 0

This is quite obscure, I may just be missing something extremely simple.

Scenario 1

Lets say I create a gradient brush, like this in my <Window.Resources> section:

<LinearGradientBrush x:Key="GridRowSelectedBackBrushGradient" StartPoint="0,0" EndPoint="0,1">
    <GradientStop Color="#404040" Offset="0.0" />
    <GradientStop Color="#404040" Offset="0.5" />
    <GradientStop Color="#000000" Offset="0.6" />
    <GradientStop Color="#000000" Offset="1.0" />
</LinearGradientBrush>

Then much later on, I want to override the HighlightBrushKey for a DataGrid. I have basically done it like this (horrible);

<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                     GradientStops="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=GradientStops}"
                     StartPoint="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=StartPoint}"
                     EndPoint="{Binding Source={StaticResource GridRowSelectedBackBrushGradient}, Path=EndPoint}" />

This is obviously not the most slick way of referencing a resource. I also came up with the following problem, which is almost identical.

Scenario 2

Say I created two colors in my <Window.Resources> markup, like so:

<SolidColorBrush x:Key="DataGridRowBackgroundBrush" Color="#EAF2FB" />
<SolidColorBrush x:Key="DataGridRowBackgroundAltBrush" Color="#FFFFFF" />

Then later on, I want to supply them in an Array, which feeds the ConverterParameter on a Binding so I can supply the custom Converter with my static resource instances:

<Setter Property="Background">
    <Setter.Value>
        <Binding RelativeSource="{RelativeSource Mode=Self}" 
                 Converter="{StaticResource BackgroundBrushConverter}">
            <Binding.ConverterParameter>
                <x:Array Type="{x:Type Brush}">
                    <SolidColorBrush Color="{Binding Source={StaticResource DataGridRowBackgroundBrush}, Path=Color}" />
                    <SolidColorBrush Color="{Binding Source={StaticResource DataGridRowBackgroundAltBrush}, Path=Color}" />
                </x:Array>
            </Binding.ConverterParameter>
        </Binding>
    </Setter.Value>
</Setter>

What I’ve done is attempt to rereference an existing resource, but in my efforts I’ve actually recreated the resource, and bound the properties so they match. Again, this is not ideal.

Because I’ve now hit this problem at least twice, is there a better way?

Thanks, Tom

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:58:46+00:00Added an answer on May 15, 2026 at 9:58 am

    I was wondering when someone was going to ask about this.

    What you want to do in Scenario 1 is to effectively give a single resource an “alias.” This is easily done by markup that seems obvious only after you see it. Suppose we have this in our App.xaml or somewhere:

    <ResourceDictionary>
      <LinearGradientBrush x:Key="GridRowSelectedBackBrushGradient" ... />
    </ResourceDictionary>
    

    To include an alias in another ResourceDictionary, just:

    <ResourceDictionary>
      <StaticResourceExtension x:Key="{x:Static SystemColors.HighlightBrushKey}"
                               ResourceKey="GridRowSelectedBackBrushGradient" />
    </ResourceDictionary>
    

    This looks up the brush object in the first ResourceDictionary and adds the same object to the second ResourceDictionary under a new key. This also works within a single ResourceDictionary.

    For your Scenario 2 the solution is just as simple:

    <Binding.ConverterParameter>
      <x:Array Type="{x:Type Brush}">
        <StaticResourceExtension ResourceKey="DataGridRowBackgroundBrush" />
        <StaticResourceExtension ResourceKey="DataGridRowBackgroundAltBrush" />
      </x:Array>
    </Binding.ConverterParameter>
    

    Again, the actual Brush objects found via the ResourceKey are added directly to the Brush[] array. No new Brush is created.

    I think we’re all so used to using StaticResourceExtension with markup extension syntax (eg {StaticResource Xyz}) that it’s easy to forget that it can also be used with regular element syntax as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
This is quite a controversial topic, and before you say no, is it really,
This isn't quite as straight forward as one may think. I'm using a plugin
I am intentionally leaving this quite vague at first. I'm looking for discussion and
I run into this quite often where a new page is supposedly tested and
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new
I know I'm not asking this quite right, either. Please help me better form
I have faced this problem quite often during the last couple of months, during
I've run into this issue quite a few times and never liked the solution
I have been hearing this term quite a lot. I have a bunch of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.