首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C# WPF -圆角背景色

C# WPF -圆角背景色
EN

Stack Overflow用户
提问于 2021-09-15 12:42:16
回答 2查看 646关注 0票数 0

我怎样才能使红色的拐角处变成圆角?我只想设置CornerRadius的MainBorder,而不是为第一个也是最后一个InnerBorder设置

如果我设置了textBlocks的背景(而不是InnerBorders),则行为是相同的

代码语言:javascript
运行
复制
<Border Name="MainBorder" Background="Transparent" Width="250" Height="250"  BorderBrush="Black" BorderThickness="3" CornerRadius="20" Margin="500,500,0,0">
            <Grid>                                                
                <Grid.RowDefinitions>                               
                    <RowDefinition Height="1*"/>                 
                    <RowDefinition Height="1*"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Border Name="brdInner1" Grid.Row="0" BorderBrush="Black" BorderThickness="0,0,0,0" Background="Transparent">
                    <TextBlock />
                </Border>
                    <Border Name="brdInner2" Grid.Row="1" BorderBrush="Black" BorderThickness="0,3,0,0" Background="Red">
                    <TextBlock />
                </Border>
                    <Border Name="brdInner3" Grid.Row="2" BorderBrush="Black" BorderThickness="0,3,0,0" Background="Red">
                    <TextBlock />
                </Border>
            </Grid>
            </Border>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-09-15 16:31:31

使用ClippingBorderhere,只需更改主边框的类型:

代码语言:javascript
运行
复制
<local:ClippingBorder x:Name="MainBorder" ...>
票数 0
EN

Stack Overflow用户

发布于 2021-09-15 17:48:12

之所以会发生这种情况,是因为虽然主边框具有CornerRadius属性集,但子边界仍然设置为正方形,但我已将CornerRadius添加到您的上一个边界控件中。

代码语言:javascript
运行
复制
<Border Name="MainBorder" Background="Transparent" Width="250" Height="250"  BorderBrush="Black" BorderThickness="3" CornerRadius="20" Margin="500,500,0,0">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <Border Name="brdInner1" Grid.Row="0" BorderBrush="Black" BorderThickness="0,0,0,0" Background="Transparent">
                <TextBlock />
            </Border>
            <Border Name="brdInner2" Grid.Row="1" BorderBrush="Black" BorderThickness="0,3,0,0" Background="Red">
                <TextBlock />
            </Border>
            <Border Name="brdInner3" Grid.Row="2" BorderBrush="Black" BorderThickness="0,3,0,0" Background="Red" CornerRadius="0,0,20,20">
                <TextBlock />
            </Border>
        </Grid>
    </Border>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69193363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档