How to detect the back or forward button in silverlight navigation software

When a page moves in silverlight, you can override this method.

protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); } 

NavigationEventArgs has a NavigationEventArgs enumeration, which is defined as

 public enum NavigationMode { New = 0, Back = 1, Forward = 2, Refresh = 3, } 

But calling e.NavigationMode always throws NotImplementedException

Is there a way in silverlight to detect that a page is moving because the user presses the browser button forward / backward.

What I'm trying to achieve is some kind of state that can be saved when the user clicks the back button.

For example, suppose you have a client page that displays a list of clients in a datagrid. The user can select a customer, and there is a detailed view that shows all the orders for this customer. Now in the order item you can click the hyperlink link, which will lead you to the delivery history of the order, which is a separate page. When the user clicks the "Back" button, I want to return to the clients page and automatically select the client that he was viewing. Is this even possible?

I also tried fragment navigation function

 NavigationService.Navigate(new Uri("#currentcustomerid=" + customer.Id.ToString(), UriKind.Relative)); 

when the customerโ€™s choice changes, but it adds too many elements to the story when the user clicks on different customers on the clientโ€™s page.

EDIT

There is also a method that you can override

 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { } 

which is the same as handling the NavigationService.Navigating event, as stated in the BugFinder response. In this method, e.NavigationMode always returns New when you click the Back or Forward button. The only time this method returns Back is when you explicitly call NavigationService.GoBack()

+6
source share
4 answers

 public enum NavigationMode { New = 0, Back = 1, Forward = 2, Refresh = 3, } 

Applies to a navigation event.

if i do

 _ns.Navigating += ns_Navigating; void ns_Navigating(object sender, NavigatingCancelEventArgs e) { if (SecurityCheck(e.Uri.OriginalString)) return; e.Cancel = true; ShowError("You are not authorised to view this page"); } 

I see that e.NavigationMode is installed. Could you do a test there?

+1
source

I don't think there are any simple ways to do this out of the box, as far as I know.

What you are trying to achieve can be easily done using the structure I created at http://ultimateframework.codeplex.com

What I did was combine the Silverlight navigation system and the prism navigation so you need the unity, prism and friendliness of mvvm.

What you want to achieve can be accomplished using the framework in the following ways.

1) Insert IsNavigationTarget and return true โ†’, which will keep the same instance when navigating through it, therefore, saving the selected / selected item.

2) Access to the onnavigatedto log to track where you came from, say / item / 1 was the previous stack, so you know that the back button was pressed from point 1.

3) You can even implement your own back / forward / refresh within the custom control provided to achieve the same result (not yet in the code)

I really use it for production code at work, and I created it, so please feel free to try it. Please note that there is an error in the version, and I still have time to release our latest build, but if you require it, I will update it for you :), just pm me.

+1
source

Set a variable in usercontrol containing a content frame that indicates which client is active.

Add a handler for the content. Navigation event in usercontrol. Use this to check a variable indicating which client is active (if the variable is non-zero) and select a client.

+1
source

Source: https://habr.com/ru/post/924285/


All Articles