locked
How to get the OnNavigatedTo()

    Question

  • I have noticed the following line from a Windows sample:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    How can I get this line to appear on my xaml page class? Excuse me if this is simple, I am used to events from a windows form; just press the lightning bolt and double click what I need.


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Tuesday, February 10, 2015 4:34 PM

Answers

  • yes you can type it in. This methods are implemented in the base class Page. They marked virtual so you can override this method to added extra funtionality. the base class will make sure the methods are called when entering the page. to demo a little how this works i maked two classes for you:
    public class Animal
        {
            public virtual void Walk()
            {
                Debug.WriteLine("animal walk");
            }
        }
    
        public class Duck : Animal
        {
            public override void Walk()
            {
                Debug.WriteLine("duck walks");
                base.Walk();
            }
        }

    and when calling:
    void Test()
            {
                // this only prints "animal walk"
                Animal a = new Animal();
                a.Walk();
    
                //this prints both
                Animal a = new Duck();
                a.Walk();
            }
        }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by UpTide Wednesday, February 11, 2015 4:10 PM
    Tuesday, February 10, 2015 4:49 PM

All replies

  • just type it in the code behind of your page?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, February 10, 2015 4:37 PM
  • When I add another kind of event it adds code to the page xaml, is there nothing to add for the OnNavigatedTo()?


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums


    • Edited by UpTide Tuesday, February 10, 2015 4:51 PM
    Tuesday, February 10, 2015 4:40 PM
  • yes you can type it in. This methods are implemented in the base class Page. They marked virtual so you can override this method to added extra funtionality. the base class will make sure the methods are called when entering the page. to demo a little how this works i maked two classes for you:
    public class Animal
        {
            public virtual void Walk()
            {
                Debug.WriteLine("animal walk");
            }
        }
    
        public class Duck : Animal
        {
            public override void Walk()
            {
                Debug.WriteLine("duck walks");
                base.Walk();
            }
        }

    and when calling:
    void Test()
            {
                // this only prints "animal walk"
                Animal a = new Animal();
                a.Walk();
    
                //this prints both
                Animal a = new Duck();
                a.Walk();
            }
        }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by UpTide Wednesday, February 11, 2015 4:10 PM
    Tuesday, February 10, 2015 4:49 PM
  • I know this doesn't have anything to do with adding that event but how does this work:

     /// <summary>
            /// Initializes the singleton application object.  This is the first line of authored code
            /// executed, and as such is the logical equivalent of main() or WinMain().
            /// </summary>
            public App()
            {
                //this.InitializeComponent();
                //this.Suspending += OnSuspending;
            }
    And the MainPage.xaml opens. How, if this is Main() and nothing is even in main, is the MainPage opening?


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Tuesday, February 10, 2015 5:37 PM
  • there is an OnLaunch method in the app.xaml.cs that let you go to the mainpage

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, February 10, 2015 9:15 PM