Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnPlatform tags not working in Xamarin Forms

I'm using Xamarin Studio 6.1, recently upgraded it to work with a Xamarin Forms project. I can't seem to get the OnPlatform tags working. I'm trying something like this

<Grid Padding="12">
    <Grid.HeightRequest>
        <OnPlatform />
    </Grid.HeightRequest>
</Grid>

The previewer immediately breaks and complains Invalid XAML: Type OnPlatform not found in xmlns="http://xamarin.com/schemas/2014/forms"

I've never seen this error before and can't find any help online. Any ideas?

like image 777
Jay Kannan Avatar asked Sep 19 '16 16:09

Jay Kannan


1 Answers

It might because of not specifiying TypeArguments. Try this:

<Grid.HeightRequest>
    <OnPlatform x:TypeArguments="x:Double"
      iOS="15" Android="10" WinPhone="10"/>
</Grid.HeightRequest>

Update:

The syntax above is deprecated. The new form is:

<Grid.HeightRequest>
    <OnPlatform x:TypeArguments="x:Double">
        <On Platform="iOS" Value="15"/>
        <On Platform="Android" Value="10"/>
        <On Platform="WinPhone" Value="10"/>
    </OnPlatform>
</Grid.HeightRequest>
like image 111
eakgul Avatar answered Sep 24 '22 18:09

eakgul