Anything similar to OnPlatform but for a specific device such as iPhone SE?

SteveRussellSteveRussell Member ✭✭✭

Is there a way, in XAML, to modify a StackLayout, for example, based on the device? For example I want my StackLayout to have extra spacing when it's on a Plus device (6 plus, 7 plus, 8 plus, XS Max)

GridLayout is proving too tedious

Tagged:

Answers

  • M_Shah04M_Shah04 USMember ✭✭✭

    Yes, you can get information about Device model using Xamarin Essentials , please refer this:
    https://docs.microsoft.com/en-us/xamarin/essentials/device-information?tabs=ios

    You can write like this:

              using Xamarin.Essentials;
    
              // Device Model (SMG-950U, iPhone10,6)
              var device = DeviceInfo.Model;
    

    After getting device model you can set property from xaml.cs.

    Hope this may solve your issue.

  • SteveRussellSteveRussell Member ✭✭✭

    Does this work with the iOS Simulator too, because I get > x86_64

    when I use:

    var device = DeviceInfo.Model;
    Debug.WriteLine("Device: " + device);

  • JohnHardmanJohnHardman GBUniversity mod

    It'll be more future-proof to have conditions based on available screen size or resolution, or on capabilities, rather than device model. Other than working around weirdness that happens on specific devices (e.g. Huawei), it's best to avoid device model wherever possible (I also recommend avoiding idiom and orientation for similar reasons).

  • SteveRussellSteveRussell Member ✭✭✭

    I'll try to use

    var width = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Width;

    and see how this works instead.

    Thank you

  • M_Shah04M_Shah04 USMember ✭✭✭

    @M_Shah04 said:
    Yes, you can get information about Device model using Xamarin Essentials , please refer this:
    https://docs.microsoft.com/en-us/xamarin/essentials/device-information?tabs=ios

    You can write like this:

              using Xamarin.Essentials;
    
              // Device Model (SMG-950U, iPhone10,6)
              var device = DeviceInfo.Model;
    

    After getting device model you can set property from xaml.cs.

    Hope this may solve your issue.

    I haven't tested but it will work with real device only.

  • SteveRussellSteveRussell Member ✭✭✭
    Tried it on a physical iPhone and it only stated “iPhone”

    I’m using DeviceDisplay instead and it works well
Sign In or Register to comment.