Arvind Chourasiya
Arvind Chourasiya

Reputation: 17422

Image BackgroundColor platform specific from xaml

I have Image control in xaml, how can I give BackgroundColor only for iOS from xaml only

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

Upvotes: 0

Views: 46

Answers (2)

In your resource dictionary, add this:

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

Then, use the resource in your image:

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

Upvotes: 1

Uraitz
Uraitz

Reputation: 496

You can add inline code in xaml

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

Upvotes: 2

Related Questions