how to refresh a page in visual studio? - windows-phone-8

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
}
}

Related

From which page navigated to a given page

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;
}
}

Windows 8.1 C# how to clear a frame after navigating to a page

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!

Windows Phone 8 : Prevent a PhoneApplicationPage from being added to backstack

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?

How to capture Url change on WP* Webbrowser Control

How can i listen the Url changes event on a Phone browser control?
My requirement is page1.html will be loaded on browser by default. On click event of Submit button on page1.html , it will redirected internally to Page2.html with some parameters. So i want to capture those parameters . How can i do this? Is there any AddressChanged event or similar events can be added ?
try this:
private void Browser_Navigated(object sender,System.Windows.Navigation.NavigationEventArgs e)
{
string uri = e.Uri.OriginalString;
}
By using Browser_Navigated and Browser_Navigating both events u can get the Uri of current navigation along with all its parameters.
There is events Navigated and Navigating, where you can get current Uri in parameters and react accordingly.

javax.swing.JDialog is appearing twice on windows device

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();
}
}