C#中使用带有圆角的边框控件的语法是什么?

huangapple go评论62阅读模式
英文:

What's the C# syntax for using a Border control with rounded corners in dotnet Maui?

问题

有人能建议一下正确的C#语法来用带圆角的Border包装一个视图吗?

我找到了很多使用XAML的例子,但我找不到任何C#的例子,也搞不清楚怎么在C#中做同样的事情(我对Maui和C#都很陌生)。

举个例子,我怎样给下面的内容添加圆角?

new Border()
{
    new VerticalStackLayout()
    {
        ...
    }
}
.StrokeShape(...这里放什么?...)

非常感谢。

英文:

Can anyone suggest the correct C# syntax for wrapping a view with a Border that has rounded corners?

I've found lots of examples using XAML, but I can't find any C# examples and can't figure out how to do the same in C# (I'm new to Maui and C#).

For example, how would I add rounded corners to the following?

new Border()
{
    new VerticalStackLayout()
    {
        ...
    }
}
.StrokeShape(...what goes here?...)

Many thanks.

答案1

得分: 4

你需要将RoundRectangle分配给你的StrokeShape。这里有一个示例,基于官方文档中的示例

Border myBorder = new Border
{
    StrokeThickness = 4,
    ...
    StrokeShape = new RoundRectangle
    {
        CornerRadius = new CornerRadius(40, 0, 0, 40)
    },
    ...
    Content = new VerticalStackLayout
    {
        ...
    }
};

这个示例创建了一个带有两个圆角的边框。如果你想要所有的角都是(统一)圆角,只需使用只接受一个参数的CornerRadius构造函数。

英文:

You need to assign a RoundRectangle to your StrokeShape. Here's an example, based on the example in the official documentation:

Border myBorder = new Border
{
    StrokeThickness = 4,
    ...
    StrokeShape = new RoundRectangle
    {
        CornerRadius = new CornerRadius(40, 0, 0, 40)
    },
    ...
    Content = new VerticalStackLayout
    {
        ...
    }
};

This example creates a border where two of the four corners are rounded. If you want all corners to be (uniformly) rounded, just use the CornerRadius constructor that takes only a single parameter.

huangapple
  • 本文由 发表于 2023年3月31日 20:22:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75898478.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定