0
votes

When navigation between pages, I pressed either start or search button which will bring me out from the app. Then when I come back to the app. It says Navigation Service null or something similar to it.

How could i solve it!?

Dispatcher.BeginInvoke(delegate()
                {
                    TextBlock b = (TextBlock)sender;

                    var CusId = (TextBlock)b.FindName("CusId");
                    var SCHTime1 = (TextBlock)b.FindName("pschtime");
                    int intCusId = Convert.ToInt32(CusId.Text);
                    string ScheduleTime = SCHTime1.Text;

                    LoginVM.GetCustomerDetail(intCusId);

                    if (LoginVM.OBCustomerDetail.Count != 0)
                    {
                        foreach (var c in LoginVM.OBCustomerDetail)
                        {
                            Common.CustomerNetworkId = c.CustomerNetworkId;
                            Common.intCustomerId = c.Id;
                            Common.CustomerName = c.Name;
                            Common.RouteId = c.RouteId.Value;
                            Common.strReportedTime = DateTime.Now.TimeOfDay.Hours + ":" + DateTime.Now.TimeOfDay.Minutes;

                        }
                        getVisitDetailNo();

                        if (VN == false)
                        {
                            myPopup.IsOpen = false;
                            backstatus = false;
                            return;
                        }
                        if (Common.visitDetailNo == null)
                        {
                            return;
                        }

                        if (LoginVM.SaveVisitedCustomer(Common.visitDetailNo, Common.strVisitHeaderNo, Common.RouteId, Common.intCustomerId, Common.SPOAccId, Common.intSalesRepId, Common.intAreaSalesManagerAccId, Common.intAreaSalesManagerId, Common.strTransactionDate, ScheduleTime, Common.strReportedTime) == true)
                        {
                            //update next Visit Detail No
                            if (UpdateVisitConfigTable() == true)
                            {
                                myPopup.IsOpen = false;
                                backstatus = false;
                                Common.urlstring = "/View/frmCustomerMenu.xaml";
                                NavigationService.Navigate(new Uri("/View/LoadingView.xaml", UriKind.Relative));

                                configVM = new ConfigViewModel();

                                //Bind Visited Outlets
                                bindVisited();
                            }
                            else
                        }
                    }


                });

The above will direct to loading.aspx and its code as below

GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Dispatcher.BeginInvoke(delegate() {
                NavigationService.Navigate(new Uri(Common.urlstring, UriKind.Relative));
            });

error comes from the loading.aspx even though i navigate away from the page before that.

![enter image description here][1]

Highlighted in Yellow- NavigationService.Navigate(new Uri(Common.urlstring, UriKind.Relative));

Common.urlstring = "/View/frmFirstTimeSync.xaml"

NavigationService = Null according to error

http://www.tiikoni.com/tis/view/?id=95ecd7b

I cannot post pictures because I do not have enough reputation

1
You need to post the exception that you are getting and the surrounding code. Are you trying to call the NavigationService in the page's Constructor? perhaps move it into the protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) method if this is the caseFunksMaName
But would this help when start or search button press? because im using a dispatcher to do my process and in the end of my process it navigates to another page inside dispatcher.gayan1991
Add some code to your question, anyone would need to see the block of code where you are performing the navigation.FunksMaName
I have added the codegayan1991
post the exception messages and point lines at which there are thrown.lisp

1 Answers

0
votes

The Above Question Runs FormLoad Method. I changed the Navigation Service Location.

Now the Navigation service works in OnNavigatedTo Method. It works Fine