Xamarin.Plugin.DeviceOrientation
Xamarin.Plugin.DeviceOrientation copied to clipboard
Comparing orientations?
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.
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 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 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.
any hint how to do this via Triggers?