Bug 34632 - Can't change IsPresented when setting SplitOnLandscape
Summary: Can't change IsPresented when setting SplitOnLandscape
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 1.5.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-10-07 11:06 UTC by John Miller [MSFT]
Modified: 2017-12-23 16:50 UTC (History)
11 users (show)

Tags: ac masterdetailpage
Is this bug a regression?: ---
Last known good build:

Test Case / Screenshots / Stack Traces / Detailed Steps to reproduce (1.85 MB, application/zip)
2015-10-07 11:06 UTC, John Miller [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description John Miller [MSFT] 2015-10-07 11:06:16 UTC
Created attachment 13222 [details]
Test Case / Screenshots / Stack Traces / Detailed Steps to reproduce


   iOS app crashes with an error "Can't change IsPresented when setting SplitOnLandscape". 

**Steps to Reproduce:**

   While ​*holding*​ tablet vertically or using the iOS iPad simulator
1. Launch app in portrait mode
2. Click “Main Page” in upper left to bring out menu
3. Click on “Modal Rotation Issue”
4. Click on “PushModal” button in the center
5. Rotate to Landscape (while still holding tablet upright)
6. Click on the button in the center
7. Click on “PushModal” button, again
8. Rotate to Portrait
9. Click on the button in the center
10. Click on “Modal Rotation Issue” from menu

The following can be tested on a device and leads to the same issue:
While tablet is laying flat on a table.
1. Launch in Landscape mode, laying down
2. Click “Modal Rotation Issue” from left menu
3. Click the “Main Page” button at the top center (which should bring out the masterdetail menu, but we are already in Landscape mode)
4. Crash!

**Actual Results:**

   The app crashes with an exception message: Can't change IsPresented when setting SplitOnLandscape

**Expected Results:**

   The app should not crash. 

**Build Date & Platform:**

   XF 1.5.0
   iOS 9

**Additional Information:**

   Attached is a zip file with everything needed to reproduce this, include a sample app, screenshots, detailed steps and stack traces to the exceptions.
Comment 2 Jason Smith [MSFT] 2015-10-10 02:00:30 UTC
SHould be fixed in 1.5.2-pre1
Comment 3 Parmendra Kumar 2015-10-20 15:12:59 UTC
I have checked this issue with Xamarin.Forms 1.5.2-pre1 and simulator and observed that its working fine on simulator.
I have also checked this issue on iPad and followed the steps provided in bug description for iPad and I am still getting exception.

Screencast: http://www.screencast.com/t/O2CO3pJw0

ApplicationOutput: https://gist.github.com/Parmendrak/c5f2be1499d3c120f75e
BuildOutput: https://gist.github.com/Parmendrak/fa779b0aa175d690f597

Hence reopen this issue against iPad.

Environment info:
Xamarin Studio 5.10 (build 824)
Mono 4.2.1 (explicit/b50293b)
GTK+ 2.24.23 (Raleigh theme)
Package version: 402010075
Xcode 7.0 (8227)
Xamarin.iOS : (Enterprise Edition)
Xamarin.Android : (Enterprise Edition)
Mac OS X 10.10.5
Comment 4 Jason Smith [MSFT] 2016-04-13 18:11:50 UTC
I tested this myself and cant repro on device.
Comment 5 uwantfries 2017-05-26 15:25:47 UTC
Can get this on UWP by creating a new MasterDetail in VS2015. The offending line of code is in the MasterPage ItemSelected:

 private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
            var item = e.SelectedItem as MasterDetailPageUWPTestMenuItem;
            if (item == null)

            var page = (Page)Activator.CreateInstance(item.TargetType);
            page.Title = item.Title;

            Detail = new NavigationPage(page);
            //IsPresented = false; <<THROWS EXCEPTION ON UWP

            MasterPage.ListView.SelectedItem = null;
Comment 6 Jose David Portuguez Wong 2017-07-11 02:12:22 UTC
I still getting this error.

I'm using visual studio 2017 and the lastest version of xamarin and if i initilize the app on landscape mode and then I change to portrait mode and i click the menu (master) I get the error "Can't change IsPresented when setting SplitOnLandscape".
Comment 7 Nicholas Bauer 2017-07-31 01:09:41 UTC
Confirmed on UWP, specifically on Windows (seemingly not Windows Phone).

IsPresented works fine if allowed to use default MasterBehavior, which appears to be a split, but fails with this exception if you explicitly set MasterBehavior to one of the Split settings and then try to change IsPresented.
Comment 8 Nicholas Bauer 2017-07-31 01:17:24 UTC
It seems it also doesn't like changing MasterBehavior on the fly--I currently am using this in the MasterDetailPage OnSizeAllocated:

if (width < WidthThreshold)
    MasterBehavior = MasterBehavior.Popover;
    MasterBehavior = MasterBehavior.Split;

The app on UWP starts up with the Master page stuck open and on top, with a Hamburger button. Attempting to click the Hamburger button leads to the exception.
Comment 9 Robert Miles 2017-08-02 01:59:20 UTC
Also hitting this as well with latest Visual Studio for Mac (7.1 Build 1289) running Xamarin.iOS with Xamarin.Forms

In my MasterDetailPage page's constructor, I'm setting...

    MasterBehavior = MasterBehavior.Split;

then, I have a function...

    public void ToggleMaster(bool show)
        if (show)
            MasterBehavior = MasterBehavior.Split;
            IsPresented = true;
            MasterBehavior = MasterBehavior.Default;
            IsPresented = false;

This bombs if I try to "ToggleMaster(false)" with the same error as others are having.
Comment 10 Robert Miles 2017-08-02 11:58:01 UTC
Sample app showing the exception when trying to hide the Master...

Comment 11 Paul DiPietro [MSFT] 2017-09-21 15:47:10 UTC
The provided reproduction link is no longer valid. Please take care to try and upload reproductions directly as attachments on the bug report as it avoids situations like this. If the issue is reproducible as of the latest 2.4.0-pre3 build, please reopen this with a working, minimized solution for us to look at. Please take note that some changes were made at a point to UWP which no longer permits the use of IsPresented in Split mode on desktop. Thanks!
Comment 12 Jose David Portuguez Wong 2017-09-21 15:57:05 UTC

For your information I Found the root cause on the Xamarin code source. 
The root cause about the try to hide presenter is that in the source code they are setting a property call CanChangePresenter to false on some part the code. but that property is never change to true in any case and the method OnIsPresentedPropertyChanging is validate is that property and if false so i will throw a error. 

Something that I did to fix was in my part of the code where I'm setting the masterbehavior or the Ispresented, cast the Page to IMasterDetailPageController and set the CanChangePresenter to true. 

I think this has to be included in the source code. Maybe in an update, just to avoid the casting. I think this have to be handle by xamarin.

there is the link of the xamarin source code: 
Comment 13 Niels 2017-12-23 16:50:16 UTC
I just hit the same error because I added the following code to the constructor of a MasterDetailPage:
MasterBehavior = MasterBehavior.SplitOnLandscape;

The constructor also contained the following code: 
this.IsPresented = false;

So you just can't do the following because it will crash when starting your app in LANDSCAPE mode:

public class MyMasterDetailPage : MasterDetailPage
  public MyMasterDetailPage()
    MasterBehavior = MasterBehavior.SplitOnLandscape;
    this.IsPresented = false; // Don't do this!

Which kind of makes sense because you are telling your app to show and hide the masterspage at the same time.