Share via


CornerRadius 结构

定义

描述圆角的特征,例如可以应用于 边框

public value class CornerRadius
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
struct CornerRadius
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
public struct CornerRadius
Public Structure CornerRadius
<CornerRadius>uniformRadius</CornerRadius>
-or-
<CornerRadius>topLeft,topRight,bottomRight,bottomLeft</CornerRadius>
- or -
<object property="uniformRadius"/>
- or -
<object property="topLeft,topRight,bottomRight,bottomLeft"/>
继承
CornerRadius
属性

示例

此 XAML 示例显示了使用不同 CornerRadius 值的几种 边框 样式:

<StackPanel>
    <Border Height="30" Width="200" CornerRadius="0"
     BorderThickness="2" BorderBrush="Red" Margin="5">
        <TextBlock>CornerRadius: 0</TextBlock>
    </Border>
    <Border Height="30" Width="200" CornerRadius="5"
     BorderThickness="2" BorderBrush="Red" Margin="5">
        <TextBlock>CornerRadius: 5</TextBlock>
    </Border>
    <Border Height="30" Width="200" CornerRadius="5,0,5,0"
     BorderThickness="2" BorderBrush="Red" Margin="5">
        <TextBlock>CornerRadius: 5,0,5,0</TextBlock>
    </Border>
    <Border Height="30" Width="200" CornerRadius="5,5,0,0"
     BorderThickness="2" BorderBrush="Red" Margin="5">
        <TextBlock>CornerRadius: 5,5,0,0</TextBlock>
    </Border>
</StackPanel>

XAML 生成此呈现的输出:

CornerRadius XAML 示例的呈现输出

注解

有关 XAML 语法的说明

尽管可以将 指定 CornerRadius 为对象元素,但不能指定单个值,例如 BottomLeft 该对象元素的 属性。 XAML 分析程序不支持为此结构设置 XAML 属性值。 例如,此 XAML 不起作用:

<!-- THIS DOES NOT WORK -->
<CornerRadius x:Key="CornerRadiusError" BottomLeft="20"/>

相反,必须将值指定为 中的 CornerRadius初始化文本。 如果要声明可由多个 Border 实例为其 Border.CornerRadius 使用的键控资源,则对 使用 对象元素语法CornerRadius非常有用。 有关 XAML 初始化文本的详细信息,请参阅 XAML 语法指南

如果指定具有两个或三个值的属性字符串或初始化文本,则仅遵循第一个值,并被视为 uniformRadius () 忽略其他值。 必须指定所有四个值才能使用与 uniformRadius 不同的行为。

可以使用空格而不是逗号作为值之间的分隔符。

此示例演示如何使用初始化文本设置资源的值 CornerRadius ,然后将资源应用于边框。

<Page.Resources>
    <CornerRadius x:Key="CornerRadius4010">40,10,40,10</CornerRadius>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Border BorderBrush="Blue" BorderThickness="2"
            CornerRadius="{StaticResource CornerRadius4010}"/>
</Grid>

CornerRadius 的投影和成员

如果使用 Microsoft .NET 语言 (C# 或 Microsoft Visual Basic) ,或 Visual C++ 组件扩展 (C++/CX) ,则 CornerRadius 具有可用的非数据成员,并且其数据成员公开为读写属性,而不是字段。 请参阅 .NET API 浏览器中的 CornerRadius

如果使用 C++/WinRTWindows 运行时 C++ 模板库 (WRL) 进行编程,则只有数据成员字段作为 CornerRadius 的成员存在,并且不能使用 .NET 投影的实用工具方法或属性。 C++ 代码可以访问 CornerRadiusHelper 类上存在的类似实用工具方法。

下表显示了 .NET 和 C++ 中可用的等效方法。

.NET (CornerRadius) C++ (CornerRadiusHelper)
CornerRadius (Double) FromUniformRadius (Double)
CornerRadius (Double、Double、Double、Double、Double) FromRadii (Double, Double, Double, Double, Double)

字段

BottomLeft

应用 的 对象的 CornerRadius 左下角的舍入半径(以像素为单位)。

BottomRight

应用 的 对象的 CornerRadius 右下角的舍入半径(以像素为单位)。

TopLeft

应用 的 对象的 CornerRadius 左上角的舍入半径(以像素为单位)。

TopRight

应用 的 对象的 CornerRadius 右上角的舍入半径(以像素为单位)。

适用于