0

我正在寻找一种颜色的前 48 像素创建一个背景,而它下面的所有内容都是另一种颜色。我创建了一种样式,但是当我尝试使用它时,它会导致手机因“XamlParseException”而崩溃。

        <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>

是否可以在 xaml 中做这样的事情,还是我需要使用图像作为背景来创建这种效果?

4

2 回答 2

2

在第 0 行创建一个 Rectangle,设置它的 Fill 属性。:) 请记住,您可以在 XAML 中分层。

于 2010-10-12T18:21:08.580 回答
1

您可以将背景设置为带有矩形的 StackPanel:

<Grid>
    <Grid.Background>
        <StackPanel>
            <Rectangle Height="48" Background="Green" />
            <Rectangle Background="Yellow" />
        </StackPanel>
    </Grid.Background>
</Grid>
于 2010-10-11T18:15:12.730 回答