Xamarin.Plugin.DeviceOrientation icon indicating copy to clipboard operation
Xamarin.Plugin.DeviceOrientation copied to clipboard

Comparing orientations?

Open memmons-ntst opened this issue 6 years ago • 4 comments

What is the correct way to do orientation comparisons? I've tried the following, none of which work:

bool fail1 = CrossDeviceOrientation.Current == 2;
bool fail2 = CrossDeviceOrientation.Current == DeviceOrientations.Portrait;
bool fail3 = CrossDeviceOrientation.Current.Equals(DeviceOrientations.Portrait);

Coming from Swift/Obj-C, I'm sure there is some dumb thing I am doing here. Also, would be great if you included an example like this in the docs.

memmons-ntst avatar Oct 18 '18 19:10 memmons-ntst

Hi @memmons-ntst

Current property has platform implementation of the plugin with interface IDeviceOrientation as a singleton, next step you will need to get CurrentOrientation value and compare with DeviceOrientations enum value:

CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait

wcoder avatar Oct 19 '18 08:10 wcoder

@wcoder can I also do this check in pure XAML? I want to set Margin/Padding based on Idiom and Orientation status. Currently I do this in code at OnSizeAllocated but here I can't use XAML Reloader tools to see the output if I change values, here I have to compile the app again and run it again.

MagicAndre1981 avatar May 02 '19 07:05 MagicAndre1981

@MagicAndre1981 plugin doesn't provide any solutions out of the box for support from XAML.

I think you can implement your case via Xamarin.Forms Triggers.

wcoder avatar May 10 '19 20:05 wcoder

any hint how to do this via Triggers?

MagicAndre1981 avatar May 12 '19 08:05 MagicAndre1981