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

Xamarin Forms:如何在CarouselPage中用OnIdiom设置gl_CarouselIndicator

当然可以实现!

完全没问题,OnIdiom 就是专门用来针对不同设备类型(手机、平板、桌面等)设置不同属性值的工具,刚好适配你这个场景。

你只需要把原来直接赋值的 gl_CarouselIndicator="CarousellCounter1.png" 替换成 OnIdiom 的结构化写法,分别指定手机和平板对应的图片资源即可。结合你给出的代码片段,修改后的写法如下:

<local:SwipePageContent 
    BackgroundImage="CRM.png" 
    IconColor="#FFF" 
    gl_CarouselIndicator="{OnIdiom Phone='CarousellCounter1.png', Tablet='CarousellCounterTablet.png'}"
    Header="{artina:Translate page1Header}" 
    Text="{artina:Translate page1Description}" 
    TextLine2="{artina:...}" />

关键说明:

  • 你可以根据实际需求替换 Tablet 对应的图片名称(比如我这里写的 CarousellCounterTablet.png),只要确保图片资源存在于你的项目对应位置即可。
  • 如果还需要支持其他设备类型(比如桌面),直接在 OnIdiom 里追加对应的键值对就行,比如 Desktop='CarousellCounterDesktop.png'。
  • 注意保持XAML的语法正确,所有属性的引号和括号要配对,避免语法错误。

另外要确认你的项目已经正确引入了Xamarin.Forms(或.NET MAUI)的核心命名空间,不过一般新建项目时都会自动配置,所以不用额外担心。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:20:06