boop
boop

Reputation: 7788

Is it possible to reference a resource within a resource?

So I know how I can declare a resource. A Color for example

<Color x:Key="MyColorResource">#ffffff</Color>

But what if I want to use another resource within my resource. Something like this

<Color x:Key="Theme.Highlight">#ffffff</Color>
<Color x:Key="MyColorResource">{StaticResource Theme.Highlight}</Color>

Would this be possible?

Upvotes: 1

Views: 109

Answers (1)

Christlin Panneer
Christlin Panneer

Reputation: 1647

You can not directly reference inside an element.

You can reference one resource inside another resources property.

<Color x:Key="MyColorResource">#ffffff</Color>
<SolidColorBrush x:Key="MyBrushResource" Color="{StaticResource MyColorResource}" />

Note: your references should be compatible types.

Upvotes: 2

Related Questions