Search This Blog

Friday, May 5, 2017

Xamarin Forms OnPlatform samples in Xaml

** To set image width

<Image x:Name ="lstImage" Aspect="AspectFill"   HorizontalOptions="EndAndExpand" Source=  "{Binding IconUrl}">
                 <Image.WidthRequest>
                   <OnPlatform x:TypeArguments="x:Double">
                     <OnPlatform.Android>30</OnPlatform.Android>
                     <OnPlatform.iOS>30</OnPlatform.iOS>
                     <OnPlatform.WinPhone>40</OnPlatform.WinPhone>
                   </OnPlatform >
                 </Image.WidthRequest>
    </Image >

***To set background color
<StackLayout.BackgroundColor> <OnPlatform x:TypeArguments="Color"> <OnPlatform.iOS>#FF0000</OnPlatform.iOS> <OnPlatform.Android>#00FF00</OnPlatform.Android> </OnPlatform> </StackLayout.BackgroundColor>


To set  it from codebehind use:
Device.OnPlatform(..,..,..)

No comments:

Post a Comment