Forum Xamarin.Forms

Multiple windows in xamarin

AlbertoCAlbertoC ITMember ✭✭

Hi i have seen something strange in master detail page in xamarin.

when i click in a item i open two istances of windows by using navigation page
do you know when this bug will be solved in xamarin?

Best Answer


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You should post some code

  • NMackayNMackay GBInsider, University mod

    Never seen this happen in the previous and current stable version, post a repo as @AlessandroCaliaro suggests.

  • AlbertoCAlbertoC ITMember ✭✭

    This is a piece of code

    public partial class MenuView : ContentPage
    RootPage root;
    List menuItems;

        public MenuView(RootPage root)
            this.root = root;
            ListViewMenu.ItemsSource = menuItems = new List<HomeMenuItem>
                new HomeMenuItem { Title = "Giro Visite", MenuType = MenuType.GiroVisite , Icon = MenuSyncIcon },
            ListViewMenu.SelectedItem = menuItems[0];
        private async void ListViewMenu_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
            if (e.Item == null)
                await this.root.NavigateAsync(((HomeMenuItem)e.Item).MenuType);

    Where the last instruction has this code

    public async Task NavigateAsync(MenuType id)

            // Chiudo Menu laterale FlyOut/Hamburger
            IsPresented = false;
            var navigationService = ViewModelLocator.Resolve<INavigationService>();
            switch (id)
                case MenuType.GiroVisite:
                    await navigationService.NavigateToAsync<GiroVisiteViewModel>();

    In debug the code is called two times

  • AlbertoCAlbertoC ITMember ✭✭

    Only in windows platform this happens

  • NMackayNMackay GBInsider, University mod

    ListViewMenu_ItemTapped is called twice?

  • NMackayNMackay GBInsider, University mod
    Accepted Answer


    Oh, looks like a bug, fixed in 2.5.1-pre1 (bad news is that release could be Q1 of 2018).

    In the interim you could write some hack to check if the page has already been requested to disregard the navigation attempt if the Device.RuntimePlatform == Device.UWP.

  • AlbertoCAlbertoC ITMember ✭✭

    So in the maenwhile how can i workaround the problem?

  • NMackayNMackay GBInsider, University mod
    edited October 2017

    As I suggested, in my MVVM Light app I just used to check if the current page had already been requested and disregard the 2nd navigation attempt (I used this for double tap on listviews), you could use a similar workaround

    if (_navService.CurrentPageKey == ViewModelLocator.PageKeyCustomerDetail) return;
    await _navService.NavigateTo(ViewModelLocator.PageKeyCustomerDetail, customer,false);

    I had a slightly modified navigation service, I'm not sure if your using MVVM light but you get the idea.

    Another alternative is just to grab a copy of the syncfusion controls if you meet the criteria of the community licence they are free (less than x employees and turn over less than one million or something like that), try their UWP listview instead.

Sign In or Register to comment.