1

Is it possible to set a static resource to the value of another static resource? As it is possible to reference a static resource from another type of static resource it should be possible, but I can't find out how. I.e something like this:

<!-- My first value -->
<Color x:Key="MyBlueColor">#ff7db3b6</Color>
<!-- This works -->
<SolidColorBrush x:Key="MyBlueColorBrush" Color="{StaticResource MyBlueColor}"/>
<!-- But how do I do this? -->
<Color x:Key="MyOtherNameForBlueColor">{StaticResource BlueColor}</Color>
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
  • A good question would be **why** would you want to do this? You can just reference `MyBlueColor` instead of creating a brand new one. – Mike Eason Jul 08 '15 at 08:46
  • Because I'd like to but local resources in my views which refer to global resources. And just to inform you, for keeping a large amount of code organized, it's quite a common case to alias variables for better readability. – Viktor Sehr Jul 08 '15 at 08:56

1 Answers1

2

You can do this

<Color x:Key="MyBlueColor">#ff7db3b6</Color>
<StaticResource x:Key="MyOtherNameForBlueColor" ResourceKey="MyBlueColor" />
Nacho
  • 962
  • 6
  • 14
  • 1
    It yields an error in the xaml-intellisense when used: "An object of the type "System.Windows.StaticResourceExtension" cannot be applied to a property that expects the type "System.Nullable[Windows.UI.Color]". However, when executing, everything seems to work as expected. – Viktor Sehr Jul 08 '15 at 09:03
  • Yes... collateral effect – Nacho Jul 08 '15 at 09:26