代码之家  ›  专栏  ›  技术社区  ›  Willy

当背景色与边框背景色不同时,为WPF TextBlock设置左上角和右上角圆角不起作用

  •  1
  • Willy  · 技术社区  · 6 年前

    我有一个WPF文本块,我试图使它的左上角和右上角变圆,所以我将它括在一个边框内:

    <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背景色不同时,它不起作用。显示如下(请参见左上角和右上角):

    enter image description here

    它只在我将TextBlock背景色设置为透明时起作用,但我需要将其设置为与透明不同的颜色。

    1 回复  |  直到 6 年前
        1
  •  2
  •   mami    6 年前

    这是一种欺骗,但对我来说是有效的:

    <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>
    
    推荐文章