Search code examples
c#silverlightxamlwindows-phone-7xamlparseexception

WP7 Is it possible to have a two color background without using an image?


I'm looking to create a background with the top 48 pixels one color, and everything below it another color. I've created a style, but it crashes the phone with a "XamlParseException" when I try to use it.

        <Style x:Key="BackgroundStyle" TargetType="Grid">
            <Setter Property="Background">
                <Setter.Value>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="48" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0" Background="Green" />
                        <Grid Grid.Row="1" Background="Yellow" />
                    </Grid>
                </Setter.Value>
            </Setter>
        </Style>

Is it possible to do something like this in xaml, or do I need to use an image as the background to create this effect?


Solution

  • Create a Rectangle in row 0, set its Fill property. :) Remember, you can layer things in XAML.