iOS上框架的角半径无法圆角化角落

7

我将尝试为一个堆叠布局设置圆角,在安卓上可以实现,但在iOS上仍然是方形的,但它确实显示了框架阴影。

我的XAML代码如下:

<ContentPage.Content>
    <StackLayout BackgroundColor="WHITE">
        <ListView>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout>
                            <Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10">
                                <StackLayout>
                                    . . .
                                </StackLayout>
                            </Frame>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

有什么想法吗?我需要找到解决方法。 - Dan
3个回答

15

IsClippedToBounds属性设置为Frame控件:

<Frame IsClippedToBounds="True" CornerRadius="10" Padding="0" Margin="10, 10, 10, 10">
    <StackLayout>
    </StackLayout>
</Frame>

4
实际上,Frame 是圆形的而不是 StackLayout,我们只是使用 Frame 包装它,所以看起来像 StackLayout 有圆角。他们仍然显示为正方形。

Frame

<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10" HasShadow="False" BackgroundColor="Red">
    <StackLayout >
         <Label Text="{Binding}"/>
    </StackLayout>
</Frame>

enter image description here

StackLayout

<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10" HasShadow="False" >
   <StackLayout BackgroundColor="Red">
         <Label Text="{Binding}"/>
   </StackLayout>
</Frame>

enter image description here

它显示了框架阴影。

您可以通过HasShadow="False"来禁用它。


问题在于它没有包裹圆角,它在iOS上显示为正方形,而在Android上是圆形。 - Dan
@Dan,请查看截图。 - ColeX
@ColeXia-MSFT 我认为这只是一个解决方法,而不是一个解决方案,如果你正在开发跨平台应用程序。请看下面我的回答。 - Marat Gallyamov

1
实际上,我认为这是Xamarin.Forms的一个错误。UWP、Android和iOS应该表现相同,但它们并不相同。因此,为了实现相同的行为,开发人员需要使用OnPlatform功能。
这个错误在这里描述和讨论,它仍然是开放的: https://github.com/xamarin/Xamarin.Forms/issues/2405

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接