AthensTransit_Hackathon.Stops.OnNavigatedTo C# (CSharp) Метод

OnNavigatedTo() защищенный Метод

The methods provided in this section are simply used to allow NavigationHelper to respond to the page's navigation methods.

Page specific logic should be placed in event handlers for the NavigationHelper.LoadState and NavigationHelper.SaveState. The navigation parameter is available in the LoadState method in addition to page state preserved during an earlier session.

protected OnNavigatedTo ( NavigationEventArgs e ) : void
e NavigationEventArgs Provides data for navigation methods and event /// handlers that cannot cancel the navigation request.
Результат void
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);
            //Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
           
            string currentBusNumber = (from b in App.activeBus
                                   select b.FirstAttribute.Value).ToList()[0];
            string stopName = "";
            
            SolidColorBrush scb = new SolidColorBrush(Colors.Transparent);
            TextBlock tbHeader;

            ListBox listBox1 = new ListBox();
            listBox1.Background = scb;
            listBox1.ItemTemplate = Resources["stopsRepresentation"] as DataTemplate;
            listBox1.ItemContainerStyle = Resources["styleOfListBoxSO"] as Style;
            //listBox1.Tapped += listBox1_Tapped;

            //var xd = XDocument.Load("all.xml");
            //var bus = from el in xd.Descendants("Bus")
            //          where el.Attribute("lineNumber").Value == currentBusNumber
            //          select el;


            int stopsCount = App.activeBus.Descendants("Stops").Count();



            var listFromStart = App.activeBus.Descendants("Stops").Take(1).Elements("Stop").ToList();
            List<Stop> myList1 = new List<Stop>();

            for (int i = 0; i < listFromStart.Count; i++)
            {
                stopName = listFromStart[i].Attribute("stopName").Value;

                var aaaaa = listFromStart[i].Elements("C").ToList();
                List<string> tempList = new List<string>();

                foreach (var innerStop in aaaaa)
                {
                    tempList.Add(innerStop.Value);
                }

                if (i==0)
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, -1));
                else if (i == listFromStart.Count - 1)
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, 1));
                else
                    myList1.Add(new Stop(stopName, tempList, tempList.Count, 0));
                //myList1.Add(new Stop(stopName, tempList, tempList.Count));
            }


            listBox1.ItemsSource = myList1;
            listBox1.Tapped += listBox1_Tapped;
            currentBusNumber = App.ChangeEnglishLettersToGreek(currentBusNumber);
            if (stopsCount == 1)
            {
                tbHeader = new TextBlock { Text = "Κυκλική \"" + currentBusNumber + "\"", FontSize = 28 };
            }
            else
            {
                tbHeader = new TextBlock { Text = "Αφετηρία \"" + currentBusNumber + "\"", FontSize = 28 };
            }
            pivotStops.Items.Add(new PivotItem()
            {
                Name = "PivotItem1",
                Header = tbHeader,
                Content = listBox1
            });

            if (stopsCount == 2)
            {
                //currentBusNumber = (string)e.Parameter;
                ListBox listBox2 = new ListBox();
                listBox2.Background = scb;
                listBox2.ItemTemplate = Resources["stopsRepresentation"] as DataTemplate;
                listBox2.ItemContainerStyle = Resources["styleOfListBoxSO"] as Style;

                var listFromFinal = App.activeBus.Descendants("Stops").Reverse().Take(1).Elements("Stop").ToList();

                List<Stop> myList2 = new List<Stop>();

                for (int i = 0; i < listFromFinal.Count; i++ )
                {
                    stopName = listFromFinal[i].Attribute("stopName").Value;

                    var aaaaa = listFromFinal[i].Elements("C").ToList();
                    List<string> tempList = new List<string>();

                    foreach (var innerStop in aaaaa)
                    {
                        tempList.Add(innerStop.Value);
                    }

                    //myList2.Add(new Stop(stopName, tempList, tempList.Count, 0));

                    if (i == 0)
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, -1));
                    else if (i == listFromFinal.Count - 1)
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, 1));
                    else
                        myList2.Add(new Stop(stopName, tempList, tempList.Count, 0));
                }
                listBox2.ItemsSource = myList2;
                listBox2.Tapped += listBox1_Tapped;
                currentBusNumber = App.ChangeEnglishLettersToGreek(currentBusNumber);

                tbHeader = new TextBlock { Text = "Τέρμα \"" + currentBusNumber + "\"", FontSize = 28 };
                pivotStops.Items.Add(new PivotItem()
                {
                    Name = "PivotItem2",
                    Header = tbHeader,
                    Content = listBox2
                });
            }
            currentBusNumber = "";
        }