Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go to first page in C# WPF

Tags:

c#

wpf

I am using navigation services in WPF. For navigating to page I use:

this.NavigationService.Navigate(new MyPage());

For going back I use:

this.NavigationService.GoBack();

But how do I go back to the first page (Home button) without using

this.NavigationService.Navigate(new FirstScreen());

Because I do not wish to create new first page, just go back to it? And I don't always open new screens in the same order.

like image 202
Dim Avatar asked May 29 '13 09:05

Dim


People also ask

WHAT IS &N in C?

&n writes the address of n . The address of a variable points to the value of that variable.

How do you jump to a line in Visual Studio?

The Go To Line dialog box lets you move to a specific line in the active document. To access this dialog box, open a document for editing, and then select Edit > Go To > Go To Line or press Ctrl+G.

How do you go back in Visual Basic?

By default, Alt+Left navigates back, and if you remove the Alt+Right shortcut for Edit. CompleteWord in Microsoft Visual Studio, Alt+Right navigates forward.


2 Answers

One way could be to use method RemoveBackEntry until there is only a single entry left in the back stack of navigation service. Once there is only a single entry simple do Navigation.GoBack()

like image 197
Haris Hasan Avatar answered Oct 24 '22 15:10

Haris Hasan


Here's a potential solution, however there may be a 'best practice' method that i'm not currently aware of:

while(this.NavigationService.CanGoBack)
{
   this.NavigationService.GoBack();
}

CanGoBack returns true if there are entries in the back navigation history and as such GoBack() will be executed until it returns false. In theory this should get you back to the origin, or in other words the first page.

like image 35
Jamie Keeling Avatar answered Oct 24 '22 15:10

Jamie Keeling