views:

309

answers:

1

I know I can write a Setter in Silverlight like this:

<Setter Property="Background" Value="{StaticResource MyBrush}" />

However, due to other considerations, I have to write the setter in the format:

<Setter Property="Background">
  <Setter.Value>
      ????? static resource
  </Setter.Value>
</Setter>

Any examples I've seen have the value set as the full brush but I want to use an existing resource and I don't know how to write it. Its not just brushes, I'm having trouble with the concept in general trying to work out the right type of property to try and set the value for. Any tips?

Jeff

+2  A: 

Any markup extension, denoted by {XXX} can be written as <XXX>. Here, {StaticResource MyBrush} is in fact creating an object of type StaticResourceExtension, passing "MyBrush" as the only argument of its constructor, which itself sets the ResourceKey property of the object. You can achieve the same effect by using:

<StaticResource ResourceKey="MyBrush" />

If you don't know what type a property is, simply set your caret on the property you're interested in and press F1 to open the help in Visual Studio which should provides you with the information you're seeking.

Julien Lebosquain
This isn't working. I should have specified I am using Silverlight instead of just saying XAML. It looks like this construct is not available in Silverlight.
Jeff