Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a color as a static resource

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?

like image 236
Michael Goldshteyn Avatar asked Jan 24 '11 19:01

Michael Goldshteyn


People also ask

What does static resources mean?

Static resources are resources not assigned to a path network and therefore do not visibly move. A static resource may be needed to perform an operation at only one location, such as an inspection operator, and will appear during the entire simulation in the same place it was defined graphically.

What is the difference between static and dynamic resources?

Static Resources retrieved once by referencing element and used for the lifetime of the resources. Whereas, DynamicResources retrieve every time they are used. The downside of Dynamic resources is that they tend to decrease application performance.

Are resources static?

Static resources allow you to upload content that you can reference in a Visualforce page, including archives (such as . zip and . jar files), images, style sheets, JavaScript, and other files. Static resources can be used only within your Salesforce org, so you can't host content here for other apps or websites.


1 Answers

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>
like image 85
Fredrik Hedblad Avatar answered Oct 12 '22 12:10

Fredrik Hedblad