将颜色定义为静态资源

Mic*_*eyn 6 c# wpf wpf-4.0 c#-4.0

我希望能够做到以下几点:

...
<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>
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不得不这样做:

...
<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>
Run Code Online (Sandbox Code Playgroud)

因为,似乎价值转换器没有踢.这是臀部的皇家痛苦,我想知道我能做什么,以便我可以象征性地和十六进制值定义我的颜色?

Fre*_*lad 7

我不确定我理解你的问题.我试过这个并且它正在工作.你是如何使用色彩资源的?

<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>
Run Code Online (Sandbox Code Playgroud)