Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.Essentials reports wrong Orientation on emulator

PaulSinnemaPaulSinnema NLMember ✭✭✭
edited May 22 in Xamarin.Forms

I've created this very little application that should tell me the orientation of the device using Xamarin.Essentials. It works fine on my Huawei P30 Pro Phone. Is this an emulator related problem?

The Emulators are the Pixel_3_q_10_0_-_api_29 and tablet_m-dpi_10_1in_pie_9_0

Here's the code:

using System.ComponentModel;
using Xamarin.Forms;

namespace OrientationProblem
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            Xamarin.Essentials.DeviceDisplay.MainDisplayInfoChanged += DeviceDisplay_MainDisplayInfoChanged;

            Orientation.Text = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Orientation.ToString();
        }

        private void DeviceDisplay_MainDisplayInfoChanged(object sender, Xamarin.Essentials.DisplayInfoChangedEventArgs e)
        {
            Orientation.Text = e.DisplayInfo.Orientation.ToString();
        }
    }
}


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="OrientationProblem.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Label x:Name="Orientation"
               HorizontalOptions="Center"
               VerticalOptions="CenterAndExpand"
               FontSize="Large"/>
    </StackLayout>

</ContentPage>

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    There could be some differences of orientation sensors between simulators and devices.
    It's better to test the physical capabilities on a real physical device.

  • PaulSinnemaPaulSinnema NLMember ✭✭✭

    I know it's better to test on a real device but this is a trivial function that should just work correctly in the emulator. It should be fixed. It really threw me off track.

  • LandLuLandLu Member, Xamarin Team Xamurai

    You could raise an issue here:
    https://github.com/xamarin/Essentials/issues

Sign In or Register to comment.