When a Page is navigated to in silverlight you can override this method.
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); } The NavigationEventArgs has a NavigationMode enumeration which is defined as
public enum NavigationMode { New = 0, Back = 1, Forward = 2, Refresh = 3, } But calling e.NavigationMode always throws a NotImplementedException
Is there a way in silverlight to detect a page is being navigated to because the user hit the forward/back browser button.
What I am trying to achieve is some kind of state that can be preserved when the user hits the back button.
For example assume you have a customer page which is showing a list of customers in a datagrid. The user can select a customer and there is a detail view which shows all the orders for that customer. Now within an order item you can click a hyperlink link that takes you to the shipping history of the order which is a separate page. When the user hits the back button I want to go back to the customers page and automatically select the customer he was viewing. Is this possible at all ?
I also tried out the fragment navigation feature
NavigationService.Navigate(new Uri("#currentcustomerid=" + customer.Id.ToString(), UriKind.Relative)); when the customer selection changes but this adds too many items to the history when the user clicks various customers on the customer page.
EDIT
There is also an method you can override
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { } which is the same as handling the NavigationService.Navigating event as indicated by BugFinder's answer. In this method e.NavigationMode always returns New when when you hit the Back or Forward Button. The only time this method returns Back is when you explicitly call NavigationService.GoBack()
Answer: 1
The
public enum NavigationMode { New = 0, Back = 1, Forward = 2, Refresh = 3, } applies to the Navigating 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 can see there that e.NavigationMode is set. You could do your test there?
by : BugFinderhttp://stackoverflow.com/users/687262Answer: 2
This might be what you are looking for:
http://jakkaj.wordpress.com/2008/09/08/control-silverlight-by-using-browser-back-and-foward-buttons/
by : Gambithttp://stackoverflow.com/users/289266
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog