开发者

Defining a color as a static resource

开发者 https://www.devze.com 2023-02-07 00:09 出处:网络
I would like to be able to do the following: ... <Grid> <Grid.Resources> <Color x:Key=\"MyColor\">#FFEEDD</Color>

I would like to be able to do the following:

...
<Grid>
  <Grid.Resources>
    <Color x:Key="MyColor">#FFEEDD</Color>
    <Color x:Key="MyOtherColor">Green</Color>
    <!-- Use MyColor and MyOtherColor to define other resources... -->
  </Grid.Resources>
</Grid>

Unfortunately, I am forced to do this instead:

...
<Grid>
  <Grid.Resources>
    <Color x:Key="MyColor" A="255" R="255" G="238" B="221" />
    <Color x:Key="MyOtherColor" A="255" R="0" G="128" B="0" />
    <!-- Use MyColor 开发者_运维百科and MyOtherColor to define other resources... -->
  </Grid.Resources>
</Grid>

Because, it seems that value converters are not kicking in. This is a royal pain in the rump and I was wondering what I can do, so that I can define my colors symbolically and by hex value?


I'm not sure I understand your problem. I tried this and it's working. How are you using your Color Resources?

<Grid>
    <Grid.Resources>
        <Color x:Key="MyColor">#FFEEDD</Color>
        <Color x:Key="MyOtherColor">Green</Color>
    </Grid.Resources>
    <Rectangle>
        <Rectangle.Fill>
            <SolidColorBrush Color="{StaticResource MyColor}"/>
        </Rectangle.Fill>
    </Rectangle>
</Grid>
0

精彩评论

暂无评论...
验证码 换一张
取 消