首页 > 解决方案 > 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?

标签: c#wpfxaml

解决方案


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.


推荐阅读