문제

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?

도움이 되었습니까?

해결책

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

다른 팁

You could set your background to be a StackPanel with Rectangles:

<Grid>
    <Grid.Background>
        <StackPanel>
            <Rectangle Height="48" Background="Green" />
            <Rectangle Background="Yellow" />
        </StackPanel>
    </Grid.Background>
</Grid>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top