【问题标题】:Image BackgroundColor platform specific from xaml特定于 xaml 的图像 BackgroundColor 平台
【发布时间】:2019-04-26 10:31:50
【问题描述】:

我在 xaml 中有Image 控件,我怎样才能只为 xaml 中的 iOS 提供BackgroundColor

<Image BackgroundColor="Green" Source="bell.png" Grid.Row="0" Grid.Column="0" 
HorizontalOptions="End" VerticalOptions="Center" >
</Image>

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    您可以在 xaml 中添加内联代码

    <Image  BackgroundColor="{ x:OnPlatform iOS='Green', Default='White'}">
    </Image>
    

    【讨论】:

      【解决方案2】:

      在您的资源字典中,添加以下内容:

      <OnPlatform x:Key="MyBackgroundColor" x:TypeArguments="Color">
          <On Platform="iOS">Green</On>
          <On Platform="Android">Transparent</On>
          <On Platform="Windows">Transparent</On>
      </OnPlatform>
      

      然后,使用图片中的资源:

      <Image
          BackgroundColor="{StaticResource MyBackgroundColor}"
          ... />
      

      【讨论】:

        猜你喜欢
        • 2016-12-16
        • 2021-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-09
        • 2023-02-07
        相关资源
        最近更新 更多