views:

320

answers:

1

I'm trying to use a StaticResource in a ControlTemplate for a custom object, and whenever that object is rendered, the application crashes. As you can see in the code below, I define both the template and the resource in App.XAML. I've been doing a bit of searching to see if/why this isn't allowed, but have had no luck so far.

    <Color x:Key="PersonBackground">#FF003B00</Color>

    <ControlTemplate x:Key="PersonTemplate" TargetType="this:Person">
        <Border Background="{StaticResource PersonBackground}" BorderBrush="White" 
                BorderThickness="2" CornerRadius="10" MinHeight="70" MinWidth="120">
    ...
    </ControlTemplate>

If anyone could explain why this isn't allowed or what I'm doing wrong (or, best yet, a better way to do custom theming in Silverlight), I would greatly appreciate it.

Edit: I feel like I should specify that I'm mostly just interested in being able to set the color scheme in one place; the rest of the theme won't need to change as much.

+1  A: 

Instead of Color, can you try using a SolidColorBrush

<SolidColorBrush x:Key="PersonBackground" Color="#FF003B00"/>

Paully
Wow, I'm amazed that I didn't catch that. Silverlight really needs to work on its error messages...Since I asked this question, I discovered TemplateBindings, which are more in line with what I want to do.Thanks!
oltman
LOL no problem! It happened to me but now I know almost everything needs brush.
Paully