WinPhone & Win 8.1: Crash on Navigation.PopModalAsync() if the page contains and Editor

I have a xaml page “Details_View” showed with ContentPage.Navigation.PushAsync(Details_View) with an Editor inside.

If I call Navigation.PopModalAsync() the app crashes (happens only on WinPhone and Win8.1. With Andro & iOS is OK) with the following exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.WinRT.EditorRenderer.OnLostFocus(Object sender, RoutedEventArgs e)

If I remove the Editor the app don’t crash any more.

Any idea?

May be a good idea try to override Xamarin.Forms.Platform.WinRT.EditorRenderer.OnLostFocus()?

Posts

  • AleStrAleStr ITMember

    Mhhh, Xamarin.Forms.Platform.WinRT.EditorRenderer don't have the OnLostFocus() method...

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @Alestr: I don't know, which XF-Version you use, but I also have the crash with PopModalAsync() (also by press of the HW-back-button) only in WP. I'm waiting over a month now for a fix.
    See also here:
    http://forums.xamarin.com/discussion/46862/xamarin-forms-1-4-4-released#latest

  • AleStrAleStr ITMember

    I don't know, which XF-Version you use

    1.4.2

    I'm waiting over a month now for a fix.

    :-(

  • ylemsoulylemsoul RUMember ✭✭✭

    @FredyWenger, describe your problem with WP modal navigation. There are several workarounds for WP (I'm using it). (I believe you mean WP 8 Silverlight, not WP 8.1 RT).
    Things to try:
    1) if you've wrapped MasterDetailPage with NavigationPage then don't wrap Detail with it.
    2) if you've not wrapped MD page with NavigationPage then wrap Detail with NavigationPage.
    i.e.


    or


  • AleStrAleStr ITMember

    I must fix the problem also on Win 8.1 because my app must run on Win tablets.
    I verified that the problem occurs only when the page contains an Editor control! For the moment I used an Entry control instead of Editor one for Win 8.1 as workaround. I'm testing it on WP 8.0.
    Is not exactly what I need but for the moment should be ok.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @ylemsoul:

    First thanks for your suggestions and your try to help me :smile: (especially as I don't have received any real help from Xamarin yet (current state see end of the posting)).
    Second sorry for the late response (I'm busy with other urgent work right now).

    My project is on WP 8.1 Silverlight (it was on WP 8.0 before, then I have updated to WP 8.1 (over the solution explorer - right mouse update to WP 8.1 - the names are confusing b.t.w.).
    Note: I also had the crash before the update the project from 8.0 to 8.1.

    My apps (including WP) are in the shops based on 1.4.3-pre-3 - the WP app based on 1.4.3-pre-3 don’t crash.
    Since I have updated from 1.4.3.pre-3 to 1.4.4-pre-3 I have the bug (crashes).

    Below, I try to describe the problem as good as possible...

    I don’t have a problem (crash) in the MD navigation itself.
    I have the crashes, if a further content-page is called from a detail-page in the MD navigation. The app then crashes as soon as page directly called from a detail of the MD navigation is released (it seems, regardless, if the page is modal or not).
    If I release a modal page with PopModalAsyc() or if I press the HW back button (to a modal or not modal page) from a "third" page, the app crashes.

    Example:
    MD is showed

    • Menu to detail1 is tapped
    • Detailpage1 is showed (no problem)
    • Tap on menu-button
    • Menu is showed
    • Menu to detail2 is tapped
    • Detailpage2 is showed (no problem)
    • ...and so on… the MD natvigation itself is not the problem
    • Menu to Detailpage1 is tapped
    • Detailpage1 is showed (no problem)

    Problem HW back button:
    - an item of a Listview on Detailpage1 is tapped
    - a further Detail-page (Contentpage) - we name it Detailpage1-1 - is showed
    - HW-Back is pressed -> App crashes

    • an item of a Listview on Detailpage1 is tapped
      • a further Detail-page (Contentpage) - we name it Detailpage1-1 -is showed
      • a button is tapped - a further Detail-page (Contentpage) - we name it Detailpage1-1-1 -is showed
      • HW-Back is pressed -> App don’t crash
      • Detailpage1-1 appears
      • HW-Back is pressed once again -> App crashes

    Problem PopModalAsync:
    - the search-icon on Detailpage1 is tapped
    - the Search-page is showed modal
    - the user select his search-items

    • the user taps on button “Cancel” or “Search”
      -> in both cases, the (modal) page is released with PopModalAsync()
      -> in both cases, the app crashes
      -> the app also crashes, if the HW back button is pressed (instead of “Cancel” or Search”)

    So my conclusion for now:
    The MD navigation itself work.
    As soon as a further Contentpage - called from a Detail-page of the MD navigation - is released (with HW back-button or PopModalAsync() (if it is a modal page), the app crashes.
    If a second Contentpage2 is called from a Contentpage1 and the HW button is pressed, the app don’t crash.

    Code:

    In the event-handler to the search-icon on a Detail-page (of the MD navigation) I push the search-page with:

    await this.Navigation.PushModalAsync(new MG_SuchenPage()); 
    

    Note: MG_Suchen Page is declared as ContentPage.

    The Search-page is showed…

    The user tap on button “Search” or “Cancel”
    I release the page with:

    await this.Navigation.PopModalAsync(); 
    

    The app crashes with error message:

    System.InvalidOperationException ist aufgetreten.
    Message: Eine Ausnahme (erste Chance) des Typs "System.InvalidOperationException" ist in System.Windows.ni.dll aufgetreten.
    Zusätzliche Informationen: Element is already the child of another element.

    If I press the HW back button on the search-page - exactly same behavior:
    The app crash with error message:

    System.InvalidOperationException ist aufgetreten.
    Message: Eine Ausnahme (erste Chance) des Typs "System.InvalidOperationException" ist in System.Windows.ni.dll aufgetreten.
    Zusätzliche Informationen: Element is already the child of another element.

    History and current status with Xamarin:
    First time reported new bug in Forum: July 23.
    Escalated problem via “success manager” to Xamarin: August 19:
    Last feedback from Xamarin :August 31:

    “Regarding the PopModalAsync() issue on WP, one of our other engineers was able to confirm the crash and will be bring up the issue to the Forms team directly”

    Do you have any further idea??
    Thanks for your time

  • ylemsoulylemsoul RUMember ✭✭✭
    edited September 2015

    @FredyWenger, I saw this exception. Just try what suggested. If you push with PushModalAsync() then wrap your MainPage with NavigationPage xor MD's Detail with NavigationPage

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @ylemsoul:

    My MD pages are relatively complex.
    Below, I have tried to strip down the code to the relevant lines...

    In App.cs:

    MainPage = new HauptSeite();
    

    In HauptSeite.cs:

    public class HauptSeite : MasterDetailPage
    {
      MenuOption previousItem;
    //
       public HauptSeite()
       {
    //...
         var optionsPage = new MenuSeite { }; // page with a LV as menu
    //…
         optionsPage.Menu.ItemTapped += (sender, e) => NavigateTo(e.Item as MenuOption);
    //…
      NavigateTo(optionsPage.Menu.ItemsSource.Cast<MenuOption>().First());
       }
    
      void NavigateTo(MenuOption option)
      {
    //…
        previousItem = option;
        var displayPage = PageForOption(option); 
        Detail = new NavigationPage(displayPage) {};
    //…
        Page PageForOption(MenuOption option)
        {
    //…
          if (option.Titel == "FreizeitGuide") // One example
          {
    //     return new EmpfehlungenPage(cURL, cTitel); // old version
           return new NavigationPage(new EmpfehlungenPage(cURL, cTitel)); // New -> same behaviour (crash)
          }
       }
      }
    }
    

    Class MenuOption:

    public class MenuOption
    {
      public string Titel { get; set; }
      public string IconSource { get; set; }
      public Xamarin.Forms.ImageSource IconSourceImage { get; set; }
      public string Details { get; set; }
      public bool Selektiert { get; set; }
    }
    

    So, I already had:

    Detail = new NavigationPage(displayPage) {};
    

    If I change additionally:

       return new EmpfehlungenPage(cURL, cTitel); // old version
    

    to:

     return new NavigationPage(new EmpfehlungenPage(cURL, cTitel)); // New -> same behaviour (crash)
    

    This don't change the behavior...

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @ylemsoul and at all other readers of this thread.
    An update to 1.4.4 "stable", that fix this bug, should be underway...

Sign In or Register to comment.