Xaml TextBlock set round corner

后端 未结 3 1223
北荒
北荒 2021-02-04 00:32

I am trying to set rounded corner of TextBlock in xaml. But there is no such property.


           


        
相关标签:
3条回答
  • 2021-02-04 00:39

    Use Border:

        <Border Margin="5" Padding="5" BorderThickness="1" BorderBrush="Red" Background="AntiqueWhite" CornerRadius="10">
            <TextBlock Text="Lorem ipsum"/>
        </Border>
    
    0 讨论(0)
  • 2021-02-04 00:51

    for that use the Border element as a parent of textBlock as like,

     <Border BorderThickness="1" BorderBrush="Black" Background="Green" CornerRadius="5">
        <TextBlock Text="Description"/>
    </Border>
    

    you already got it. :)

    0 讨论(0)
  • 2021-02-04 01:00

    TextBlock do not have such property, however you can do it like this using Rectangle's RadiusX and RadiusY property by binding the width and height of Rectangle to Textblock Width and height.

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Name="textBlock" Padding="5,0" Text="This is my TextBlock" Height="30" Width="Auto" VerticalAlignment="Top"/>
            <Rectangle RadiusX="5" RadiusY="5" Width="{Binding Width,ElementName=textBlock}" Height="{Binding Height,ElementName=textBlock}" Stroke="White" StrokeThickness="3" VerticalAlignment="Top"/>
    </Grid>
    
    0 讨论(0)
提交回复
热议问题