ja13
ja13

Reputation: 89

Navigating between pages in WPF

Is there any posibility to keep content of page after navigate of it. For example I have Window with frame and few buttons and every button navigate on some page.

frame.Navigate(new Page1()); //every button for different page

Now one page for example have some textblock and button. If a click on button text of textblock change. When I go to some other page and come back to that page the textblock.Text will not be saved, it will back to default value? How to keep it?

I know in wp 8.1 you can do it with this line of code in constructor:

this.NavigationCacheMode = NavigationCacheMode.Required;

but, I can't find how to the the same in WPF.

Upvotes: 2

Views: 1916

Answers (3)

Danil Shaykhutdinov
Danil Shaykhutdinov

Reputation: 2287

You can use KeepAlive = true; property inside each page that you want cache in back stack.

Upvotes: 0

Kim Homann
Kim Homann

Reputation: 3229

You could use an overloaded version of Frame.Navigate():

public bool Navigate(
    object content,
    object extraData
)

In the extraData, you can pass a param to the page you want to navigate to, usually a string. And the info you place in this string can be used by the loaded page to initialize itself with the desired data.

Upvotes: 0

ViVi
ViVi

Reputation: 4464

The idea behind it is very simple. The data is not being stored in the page since when you navigate to the page, a new instance of the page is being created.

You can do so by maintaining a static instance of the page. ie the page is created only the first time the application is run. The next time you load the page, the state will be maintained.

Upvotes: 1

Related Questions