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

.NET MAUI iOS中渐变背景绑定导致应用崩溃的问题

.NET MAUI iOS端绑定动态渐变颜色崩溃问题(Android端正常)

近几日在.NET MAUI的iOS端实现渐变背景时,应用出现崩溃问题,但Android端运行完全正常。

导致崩溃的测试代码(绑定动态颜色)

<Grid HeightRequest="316" HorizontalOptions="Fill">
  <Grid.Background>
   <LinearGradientBrush EndPoint="0,1">
     <GradientStop Color="{Binding myStartColor}"
                   Offset="0.1" />
     <GradientStop Color="{Binding myEndColor}"
                   Offset="1.0" />
    </LinearGradientBrush>
  </Grid.Background>
</Grid>

如上所示,通过数据绑定设置GradientStop的Color属性会导致iOS端应用崩溃。

对应的ViewModel代码

public class myDemoModel : BindableBaseObject
{
    public Color myStartColor { get; set; }
    public Color myEndColor { get; set; }
}

已在Grid、VerticalStackLayout、BoxView(另有问题将另开帖讨论)上测试,表现均类似。

可正常运行的静态颜色代码

<Grid HeightRequest="316" HorizontalOptions="Fill">
  <Grid.Background>
   <LinearGradientBrush EndPoint="0,1">
     <GradientStop Color="Red"
                   Offset="0.1" />
     <GradientStop Color="Green"
                   Offset="1.0" />
    </LinearGradientBrush>
  </Grid.Background>
</Grid>

除BoxView外,静态颜色值的渐变背景均可正常工作,但需求是实现颜色的动态修改。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 00:22:10