You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在XAML Style中设置Clip属性实现视图裁剪?

你需要把Clip对应的EllipseGeometry对象嵌套在Setter.Value节点内赋值,完整的可复用样式代码如下:

<Style TargetType="Image" ApplyToDerivedTypes="True" x:Key="roundedImageStyle">
    <Setter Property="HeightRequest" Value="75"/>
    <Setter Property="WidthRequest" Value="75"/>
    <Setter Property="Aspect" Value="AspectFit"/>
    <Setter Property="Clip">
        <Setter.Value>
            <EllipseGeometry
                Center="37.5,37.5"
                RadiusX="37.5"
                RadiusY="37.5" />
        </Setter.Value>
    </Setter>
</Style>

使用时直接给Image控件绑定样式即可,无需重复写裁剪逻辑:

<Image Style="{StaticResource roundedImageStyle}" Source="图片资源路径"/>

如果后续需要调整圆形图像的尺寸,只需要同步修改HeightRequest、WidthRequest的值,以及EllipseGeometry的Center、RadiusX、RadiusY的数值为宽高的1/2即可。

内容的提问来源于stack exchange,提问作者Juan Sturla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 02:24:07