2011-01-24 98 views
6

我想能夠做到以下幾點:定義顏色作爲靜態資源

... 
<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> 

不幸的是,我不得不這樣做,而不是:

... 
<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> 

因爲,似乎價值轉換器沒有踢。這是臀部的皇家痛苦,我想知道我能做什麼,以便我可以用十六進制值來象徵性地定義我的顏色?

+0

我只見過第一種方式。我甚至不知道你可以做第二種方式。 – Gabe 2011-01-24 20:22:24

+0

看起來問題是由於構建問題造成的,VS2010設計器與XAML不同步。感謝Meleak在一個單獨的項目中進行測試。 – 2011-01-24 20:34:01

回答

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>