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

Your project is not referencing the "MonoAndroid,Version=v8.1" framework. Add a reference to "MonoAndroid,Version=v8.1" in the "frameworks" section of your project.json, and then re-run NuGet restore.

I had  the same problem. Reason: file obj/project.assets.json target "MonoAndroid,Version=v7.1" when my project target androi...