英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论