【问题标题】:Setting top left and right rounded corners for WPF TextBlock not working when background color is different from border background color当背景颜色与边框背景颜色不同时,为 WPF TextBlock 设置左上角和右上角圆角不起作用
【发布时间】:2019-06-01 01:10:10
【问题描述】:

我有一个 WPF TextBlock,我试图将它的左上角和右上角变成圆形,所以我将它包围在边框内:

<Border CornerRadius="10 10 0 0" 
        BorderThickness="2" 
        BorderBrush="DarkBlue"
        Margin="10 15 10 0">
    <TextBlock Text="This is a TextBlock with rounded top left and top right corners" 
               Background="Yellow" 
               Foreground="Black" 
               TextAlignment="Center" />
</Border>

这种方法的问题是当边框背景颜色与TextBlock背景颜色不同时,它不起作用。显示如下(见左上角和右上角):

仅当我将 TextBlock 背景颜色设置为透明时才有效,但我需要将其设置为不同于透明的颜色。

【问题讨论】:

    标签: wpf visual-studio-2008 .net-3.5 textblock cornerradius


    【解决方案1】:

    这是一种作弊,但对我有用:

    <Border CornerRadius="10 10 0 0" 
            BorderThickness="2" 
            BorderBrush="DarkBlue"
            Margin="10 15 10 0"
            Background="Yellow"
            Padding="20">
            <TextBlock Text="This is a TextBlock with rounded top left and top right corners" 
               Foreground="Black" 
               TextAlignment="Center"/>
        </Border>
    

    【讨论】:

    • 咳咳,您需要从 TextBlock 中删除背景。否则,这个“作弊”就是要走的路……;-)
    • 是的,谢谢,已编辑。无论如何,它都会从边框继承背景。
    • 好的,只是在玩边框填充;)很好很酷!我没有考虑...我也在玩 TextBlock 边距,但我没有意识到我需要从 TextBlock 中删除背景并仅在 Border 中设置它,因为它是继承的。
    猜你喜欢
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2014-04-06
    • 2020-03-27
    • 2021-11-10
    • 2020-11-30
    相关资源
    最近更新 更多