views:

262

answers:

1

I am playing with templates in Silverlight 2.0. I copied this...

<Style x:Key="RoundButton">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <Ellipse Width="200" Height="200">
                        <Ellipse.Fill>
                            <RadialGradientBrush GradientOrigin=".2,.2">
                                <GradientStop Offset="0.2" Color="White" />
                                <GradientStop Offset="1" Color="Blue" />
                            </RadialGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>

                    <TextBlock Text="Push me" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

from a web page at http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx.

I put it into my app.xaml and as yet have not used it anywhere. When I try to run my code I get an error "Exception of type 'System.ExecutionEngineException' was thrown."

What have I done wrong?

+1  A: 

I believe that Silverlight requires the TargetType attribute. If you add TargetType="Button" to the Style element, it'll compile and execute without this exception.

EDIT: Yeah...I just followed the link you posted, and he has the TargetType attribute in his sample code. Add that, and you're all good. I created a simple test app with just that Style element and a button using it, and it worked fine.

Rich
D'oh! Sometimes you can't see for looking :-)
Was going to point out the missing TargetType in the Style tag, but you beat me to it
Gordon Mackie JoanMiro