x:Int16's OnIdiom

Jassim Al Rahma 1,526 Reputation points
2021-10-01T16:14:27.413+00:00

Hi,

I have this Int16 in my App.xaml

<x:Int16 x:Key="HeaderHeight">50</x:Int16>

I want to know how can I use OnIdiom with it to have it 50 for Phone and 8- for Tablet?

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Wang 5,531 Reputation points
    2021-10-04T07:14:55.273+00:00

    Hi JassimAlRahma-9056,

    Welcome to our Microsoft Q&A platform!

    Xamarin does not provide such markup. A workaround is that you can define the HeaderHeight in App.xaml for both phone and tablet.

    Then use the "HeaderHeight" via StaticResource.

    Here is a simple demo.

    App.xaml

    <Application.Resources>  
        <x:Double x:Key="HeightOnPhone">100</x:Double>  
        <x:Double x:Key="HeightOnTablet">50</x:Double>  
    </Application.Resources>  
    

    MainPage.xaml

    <BoxView Color="Blue"  
            WidthRequest="200"  
            HeightRequest="{OnIdiom 200, Phone={StaticResource HeightOnPhone}, Tablet={StaticResource HeightOnTablet}}"  
            HorizontalOptions="Center" />  
    

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments