0
void RecordButton_Click(object sender, EventArgs e)
{
    NavigationService.Navigate(new Uri("/RecordAudio.xaml",UriKind.Relative));
}

In the above code , is NavigationService a class or is it an object of type NavigationService ? .

if it is a class . then is Navigate() a static method ?

and

if it is an object . Why have we not instantiated NavigateService class using the new operator ?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
varunsinghal65
  • 536
  • 1
  • 5
  • 20

3 Answers3

0

From what i know: The NavigationService class "belongs" to the recent page you're on and it is never used "on its own". You use its methods instead, like with navigate. The page gets informed when sth. new is to display.

sebastian s.
  • 160
  • 4
  • 1
    NavigationService is a property of Page, and its type is NavigationService which you can find in System.Windows.Navigation. – Romasz Jan 16 '14 at 09:23
0

NavigationService is a non static class and so is its method Navigate. And as the method is non static, you need to create an object of the class. But the class NavigationService gets instantiated automatically when the app is run and gets attached as a property to the Frame object and hence available commonly to all the Page Object in a single frame.

refer

For Understanding The Difference between Page Frame Content and Role of the class NavigationService.

Link to a related question One

Link to a related question Two

Community
  • 1
  • 1
A.K.
  • 3,321
  • 1
  • 15
  • 27
  • Since i am a newbie , i have lots of qs : 1. How is NavigationService automatically instantiated on app run ? 2. what is frame object ? 3. And in the second last line r u saying that the instance of NavigationService class is stored in property NavigationService ? 4. And do the Frame object , Page object and many objects inside page follow some kind of heirarchy ? – varunsinghal65 Jan 17 '14 at 10:58
  • The base object that is created in an app is a frame and we get multiple pages attached in a single frame, A single frame contains multiple pages, System tray, ApplicationBar. NavigationService object binds as the property to that single frame object. The first link that I provided in my answer Explains this very well. – A.K. Jan 17 '14 at 14:26
  • Understood base object . Could u please answer the questions 1 , 3 also – varunsinghal65 Jan 17 '14 at 23:09
0

As @VahidNd said - use F12 (if you use VS). To clarify it's like this:
PhoneApplicationPage (which you use) base class is Page:

public class PhoneApplicationPage : Page
{
 // content
}

public class Page : UserControl
{
    public NavigationCacheMode NavigationCacheMode { get; internal set; }
    public NavigationContext NavigationContext { get; }
    public NavigationService NavigationService { get; }
    public string Title { get; set; }

    protected virtual void OnFragmentNavigation(FragmentNavigationEventArgs e);
    protected virtual void OnNavigatedFrom(NavigationEventArgs e);
    protected virtual void OnNavigatedTo(NavigationEventArgs e);
    protected virtual void OnNavigatingFrom(NavigatingCancelEventArgs e);
}

And you can see that it has a property NavigationService of type NavigationService which is a clss in System.Windows.Navigation.
You can see these dependences when you use this F12 key - just set cursor's position on type/property/what you want, and hit the key.

Romasz
  • 29,662
  • 13
  • 79
  • 154