0

I would like to know if there is any new way of handling to force a page to either landscape or portrait in xamarin.forms 3.0? I did manage to find some old articles on this but they refer to using methods that directly handle on each specific platforms. So, any new method in this xamarin.form 3.0?

These are my requirements:
1) Initially , all pages in iOS and Android are in Portrait Mode.
 Where and how to I set up this for iOS and Android?

2) How to I set up any page I want to display in Landscape mode when I click a button .

I saw this link with interesting approach using interface, But I dont understand how to use it.

How to set ContentPage orientation or screen orientation on perticular page in Xamarin.Forms cross platform Thanks

Thanks

MilkBottle
  • 4,242
  • 13
  • 64
  • 146
  • I don't think so. But, it's not too hard to create a `CustomView` and a `Custom Renderer` based on `ContentPage`, for example, and implement this like a property. Have you sawed [this post](https://stackoverflow.com/a/32174715/8093394)? – Diego Rafael Souza Jun 04 '18 at 03:48
  • @DiegoRafaelSouza, read the link. It seems the solution is target on a specific Page (in the example is ThirdPage) what if I need to do for other pages? – MilkBottle Jun 04 '18 at 05:52
  • Still no way to do that out of the box. The [Selvarathinam's answer](https://stackoverflow.com/a/50673362/8093394) is the way to go – Diego Rafael Souza Jun 04 '18 at 05:56

1 Answers1

0

You can include below line of code in the MainActivity class in Xamarin.Droid.

[Activity(ScreenOrientation = ScreenOrientation.Portrait, Theme = "@style/AppTheme", Label = "App", Icon = "@drawable/icon", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{}

This will force the app to stick with Portrait mode only. Hope this helps.

Selvarathinam Vinoch
  • 1,080
  • 3
  • 13
  • 23
  • This code will fixed all pages in Portrait mode. I need to display some pages in Landscape mode after clicking a button. How to Achieve this? please see my update above. – MilkBottle Jun 04 '18 at 05:54
  • You can use the answer provided by @mindOfAi. To do that, please watch this video which tells you the step by step approach on dependency service implementation. https://www.youtube.com/watch?v=lgcnYDb6cRQ – Selvarathinam Vinoch Jun 04 '18 at 06:14