I want to know from which page navigated to a given page by pressing the back button. But I didn't find a solution for it in WP8.1
Parameters can be used for forwards navigation, as I know.
Can anyone help me?
You want to know which page was displayed before the user navigated back to your current page? You can inspect Frame.ForwardStack for that:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
{
// get the type of the page that was shown previously
var navigatedFromPage = Frame.ForwardStack[0].SourcePageType;
}
}
Related
I have a SideMenu page fragment in my app. On each and every page, I have a copy of this page fragment.
My intention was to create a SideMenu with openable SubMenus (only one sub menu could be open at a time), but I could not get it done to make the app "remember" the state of the SideMenu( like which SubMenu should be open, and which ones shouldn't), because on each site there is a different widget, so when in my code ( in my onClick events) I refer to the widget, I am not handling "a global SideMenu" but rather a specific copy of it, unique to that page.
Sadly, this took several hours of debugging to realize, I am defeated.
Is there anyway to place a page fragment on a page, so I can handle that widget on its own, not just it's copies?
Thanks in advance, I can try to specify more the question if it's needed.
I agree with #MarkusMalessa. You need to invoke the widget on every page and then apply whatever change on it. I am doing the samething on a project in which I intend to shrink and expand the sideMenu. To give you an idea, evertime I click a button on the side menu responsible for the logic, this is the code that's invoked:
var pages = app.pages._values;
pages.forEach(function(page){
var sideMenu = page.descendants.sideMenu1;
if(sideMenu){
if(widget.text === "chevron_right"){
sideMenu.getElement().style.width = "300px";
} else {
sideMenu.getElement().style.width = "60px";
}
}
});
That way every sideMenu widget inside each page that has it receive the same changes.
I have a global page that hosts navigation buttons to diffeernt pages. it also hosts a frame called ContentFrame. It navigates to the diffeernt pages as the navigation buttons are clicked. But initially some calls are made to the DB and when data is returned, the ContentFrame navigates to the mainpage first.
I have a back button and a home button. When the contentframe has MainPage in it and the back button is clicked, I want the app to go back to a previous page from which this whole global page is loaded. If the content frame just has some other pages loaded, then I want it to simply go back to the previous page that was loaded when back button is clicked.
Here is my code for the contentframe in the global xaml
<Frame x:Name="ContentFrame" Grid.Row="1" Grid.Column="1" />
Here is my back button click code for global page
private void Back_Click(object sender, RoutedEventArgs e)
{
if ((ContentFrame.CurrentSourcePageType != null) && (ContentFrame.CurrentSourcePageType.Name.Equals("MainPage")) && (this.navigationHelper.CanGoBack()))
{
ResetPageCache();
this.navigationHelper.GoBack();
}
else
{
if (this.ContentFrame.CanGoBack)
{
this.ContentFrame.GoBack();
}
else if (this.navigationHelper.CanGoBack())
{
this.navigationHelper.GoBack();
}
}
}
private void ResetPageCache()
{
var cacheSize = (this.Frame).CacheSize;
(this.Frame).CacheSize = 0;
}
The issue that I am facing is that when the ContentFrame has main page loaded and back button is clicked, it navigates back to a previous page before the global page was loaded but in the process, the onnavigatedfrom() event for MainPage is not raised where I unsubscribe some events.
Any idea how I can get the onNavigatedFrom() to fire for MainPage in this case?
Thanks
The simplest solution might be to handle the Unloaded event apart from/instead of OnNavigatedFrom so that your clean up happens regardless of navigation but rather when just being removed from the visual tree. You might want to pair it with the Loaded event though in case your page gets added to the visual tree without being navigated to (e.g. when the cached parent page is being navigated to).
Sure. Do this:
var frame = Window.Current.Content as Frame;
frame.SetNavigationState(string.Empty);
Best of luck!
i have created a windows phone application. In each page i have given a back button using "NavigationService.GoBack()" command. i want that when the back button is pressed the previous page to which it navigate the whole code of that page must again be executed.
If you're relying the user pressing the hardware back button you shouldn't have to call GoBack() yourself.
To refresh a page when the user navigates back to it you can use the following in your page (and add the refresh code as appropriate):
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.Back)
{
// Do your refreshing here
}
}
I have a phone page which navigates to another. Is there a way to prevent the fist page from getting into the backstack when navigating to the second?
I'd rather not remove the first page from the backstack in the code for the second page.
The most obvious way kind of works:
NavigationService.Navigate(new Uri(...));
NavigationService.RemoveBackEntry();
But it may fail - see submision problems described here.
If you were to remove the BackStack Entry on the second page (and thus disperse the knowledge of the first page behaviour in context of navigation), you would to that in OnNavigatedTo, which occurs after the navigation is completed and the entry is placed on the BackStack. PhoneApplicationPage similarly has OnNavigatedFrom method, which is also called after the navigation is completed (OnNavigatingFrom is called before navigation and allows cancelling). So first page could remove itself in the following way:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
NavigationService.RemoveBackEntry();
}
However, this method is incomplete, as OnNavigatedFrom is called not only after a succesfull Navigate, but also after pressing any of the three device buttons or showing a Launcher or Chooser (from Microsoft.Phone.Task). In those cases current page will not be placed on the BackStack (I guess that's why the BackStack corrections are applied usually on other Pages). So to fix the above method you could check if the last entry is what it should be:
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
var entry = NavigationService.BackStack.FirstOrDefault();
if (entry != null && entry.Source.OriginalString.Contains(...))
{
NavigationService.RemoveBackEntry();
}
}
I have the same requirement when implementing a login page. Upon navigation to the authenticated area of the app, I want to remove the login page from the backstack.
To do this, I simply pop the stack after the call for the navigation out of the login view.
NavigationService.Navigate("/Page2.xaml");
NavigationService.RemoveBackEntry();
This doesn't require code in your Page2.xaml.
No, there is no way. Why won't you remove it if you don't want it to be there?
I have created a JDialog to be opened when I click on the edit button of my JFrame, it is being opened properly and does'nt have any issue, but when I took this code on the windows ce 5.0 device this dialog is being opened twice. hat is i am clicking only once on the edit button but the dialog is appearing twice, I want there should be only one dialog appear on edit button click.
ok I have got the solution
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false) {
List lsm = (List) e.getSource();
showDialog();
lsm.clearSelection();
}
}