如何在WPF中的内容上显示边框?

时间:2013-11-29 01:19:37

标签: .net wpf

我围绕ScrollViewer和TextBlock创建了一个边框,但是它们的边角略微延伸到我边框的圆角上。我怎么能让它走另一条路? 我尝试使用Panel.ZIndex,但它不起作用 这是我的代码:

<Window x:Class="MyApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Behaviors="clr-namespace:UI.Behaviors;assembly=UI.Behaviors"
    Title="My app" Height="408" Width="523" Closed="Window_Closed" Visibility="Visible"
    Behaviors:FocusBehavior.FocusFirst="True" Closing="Window_Closing">
    <Grid>
        <Border
            HorizontalAlignment="Stretch"
            Panel.ZIndex="3"
            BorderThickness="4"
            CornerRadius="10"
            BorderBrush="Black" Grid.ColumnSpan="2" Margin="12,50,8,48">
                <ScrollViewer Panel.ZIndex="2" Name="ScrollViewer1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="True" >
                    <TextBlock Background="WhiteSmoke" Panel.ZIndex="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" Name="textBlock1" Text="" />
            </ScrollViewer>
        </Border>
    </grid>
</Window>

1 个答案:

答案 0 :(得分:0)

为边框添加填充(例如“5”)并将其背景设置为与TextBlock相同(即“WhiteSmoke”)。