这是我第一次使用.NET MAUI 7.0 进行编程。我使用的是 Windows 机器。当使用以下代码时,图像的左上角被切掉了一部分。
<Border Grid.Column="1" Grid.Row="1" WidthRequest="80" HeightRequest="80" StrokeShape="Ellipse">
<ImageButton Source="image.png" WidthRequest="60" HeightRequest="60" VerticalOptions="Center" HorizontalOptions="Center"/>
</Border>
我在使用 StrokeShape="RoundRectangle 40,40,40,40" 时遇到了同样的问题。我需要完整的图像,而不是在左上角被剪掉。
这是 iOS 中的一个已知问题,已在 .NET 8 中修复,可以在此处找到更多信息:https://github.com/dotnet/maui/issues/17753
我不确定为什么要在 ImageButton 上使用边框,如果这只是为了使其成为圆形,你可以这样做:
<ImageButton
HeightRequest="50"
WidthRequest="50"
CornerRadius="25"/>
技巧是圆角半径应该是高度和宽度的一半。