Is it possible to set a static resource to the same value as another in XAML?
Asked Answered
P

1

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>
Prieto answered 8/7, 2015 at 8:42 Comment(2)
A good question would be why would you want to do this? You can just reference MyBlueColor instead of creating a brand new one.Troyes
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.Prieto
V
2

You can do this

<Color x:Key="MyBlueColor">#ff7db3b6</Color>
<StaticResource x:Key="MyOtherNameForBlueColor" ResourceKey="MyBlueColor" />
Veolaver answered 8/7, 2015 at 8:56 Comment(2)
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.Prieto
Yes... collateral effectVeolaver

© 2022 - 2024 — McMap. All rights reserved.