Silverlight StackPanel里面有圆角的边框

时间:2012-09-06 16:19:42

标签: silverlight xaml

这是如何正常处理的?我有这个xaml:

    <Border Grid.Column="1" HorizontalAlignment="Right" 
        VerticalAlignment="Top" Margin="10,25,10,0" Opacity="0.7" 
        BorderBrush="Black" BorderThickness="1" CornerRadius="5">
        <StackPanel>
            <StackPanel.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="LightGray" Offset="0.0" />
                    <GradientStop Color="Gray" Offset="1.0" />
                </LinearGradientBrush>
            </StackPanel.Background>

StackPanel的左上角和右上角是LightGray,并且看起来位于Border的顶部,因此在圆角​​Black角的中间是一个或两个LightGray像素,打破了舍入。底部边框是灰色而不是黑色。

我认为上面的代码我会得到一个圆角的StackPanel ......

1 个答案:

答案 0 :(得分:1)

我建议将背景放在边框而不是Stackpanel

<Border Grid.Column="1" HorizontalAlignment="Right" 
    VerticalAlignment="Top" Margin="10,25,10,0" Opacity="0.7" 
    BorderBrush="Black" BorderThickness="1" CornerRadius="5">
    <Border.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
            <GradientStop Color="LightGray" Offset="0.0" />
            <GradientStop Color="Gray" Offset="1.0" />
        </LinearGradientBrush>
    </Border.Background>
    <StackPanel>
        <!-- Items here -->
    </StackPanel>
</Border>