tags:

views:

241

answers:

1

Is there a way to redefine/alias an existing SolidColorBrush (or any other resource, actually)?

Case in point: I have a brush in an external ResourceDictionary that I want to reference by my own key instead of the original key. I don't want to be dependent on the external reference, since the actual brush is prone to change in the future.

+3  A: 
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
     <SolidColorBrush x:Key="SomeExternalResource">Red</SolidColorBrush>
    </Window.Resources>
    <Grid>
     <Grid.Resources>
      <StaticResourceExtension ResourceKey="SomeExternalResource" x:Key="SomeAliasedResource"/>
     </Grid.Resources>

     <Border Background="{StaticResource SomeAliasedResource}"/>
    </Grid>
</Window>

I don't want to be dependent on the external reference, since the actual brush is prone to change in the future.

You'll still be dependent on the external resource, just not in as many places.

HTH, Kent

Kent Boogaart
the only limitation to this is that you can't reference both the original and the alias if used within the same resource dictionary, as they will override each other. i am assuming this applies to multiple dictionaries you merge at application scope.
Paul Stovell
Judging by the way the question is worded, he doesn't want to reference the original - only his alias. Referencing the original would defeat the purpose of creating the alias.
Kent Boogaart
That works. Thanks!
Inferis