简体   繁体   中英

Navigation Helper C# Visual Studio 2017

I have been reading and following a book called Head First C# and in some of the exercises I have come across with something I have not being able to use: The "Navigation Helper" On the book they tell you to type the following code:

public MainPage()
{ 
   this.InitializeComponent();
   this.navigationHelper = new NavigationHelper(this)
   this.navigationHelper.LoadState += navigationHelper_LoadState;
   this.navigationHelper.SaveState += navigationHelper_SaveState;
}

I'm not sure if it is because the book is supposed to be follow using Window Store app in Visual Studio Express 2013 an I'm using Blank App(Windows Universal) in Visual Studio 2017 but for some reason I don't find the NavigationHelper Class. Am I missing some assembly perhaps? or is it the difference in the templates or versions I'm using? if that's the case does anyone knows how to use Windows Store app in VS2017? is that even possible?

I have tried to search for it but I seem not able to find anything online, so this is my last resource :) Thanks and I'll appreciate any help!

I faced the same issue as you described with "Navigation Helper". Based on the comment written by Camilo Terevinto I did some investigations and refactoring of my code. The results are below, hope it may be useful for you and others:

1) in the link quoted by Camilo there is a deep explanation of this subject and class itself. Look at the line 23-57. There, the author explained what should we do in order to use this class. Because it may be "mission impossible" for the "very beginners" to implement it, let me suggest another solution….which I checked and it worked... 2) refactor your code and comment the lines including missing class and generating errors, for instance:

this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.aveState += navigationHelper_SaveState;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    navigationHelper.OnNavigatedFrom(e);
}

This exercise ("Save the Humans" app) in the chapter 1 is rather to understand the process, XEML, etc. Later on you will understand more and more and you will figure out better solution for you.
It worked for me. Please keep on mind that it is not the best solution of the problem, but at least it will allow you to proceed with this lesson and develop this Save the Homans app. So please save us!:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM