I am developing Windows phone 8.1 Silver Light Application. In the application there are so many screens. Pages are navigating perfectly.
My issue is when i press on back button(Windows Phone Back Button) The pages are going back to the previous pages. I want to stop back button navigation in my application. I followed below link but i am not succeeded.
https://social.msdn.microsoft.com/Forums/windowsapps/en-us/131a99ce-53a4-4389-81e9-7801af57b78b/used-hardwarebuttonsbackpressed-handler
Could any one advise me.
Try this for back button on your XAML.cs page :
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
}
Related
I am working on a C# Project for WindowsPhone 8. When the user deactivates the App (i.e. Going to the main menu) I stop some timers and save some things. This works fine.
But when the user reactivates the app I want to navigate the user to a pause screen.
NavigationService.Navigate(new Uri("/Pause.xaml", UriKind.Relative));
The Code is simple and works perfect when the app isn't deactivated. But when the user reactivates the app it throws a NullReferenceException.
I already tried several things such as:
public void pause_for_activated()
{
this.Loaded += navigate_pause();
}
private RoutedEventHandler navigate_pause()
{
NavigationService.Navigate(new Uri("/Pause.xaml", UriKind.Relative));
return navigate_pause();
}
When I start the app without automatically navigating to the pause screen and then press a button to navigate it works.
My Question is now when can I automatically navigate and how can I do this ?
In advance , I thank you already.
I got no answer until now, but I found a solution for me so I decided to put it here.
Loaded += navigate_pause();
private RoutedEventHandler navigate_pause()
{
Dispatcher.BeginInvoke(() =>
{
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/Pause.xaml", UriKind.Relative));
});
return null;
}
When navigating using the webview in a Windows Store app any links which try to open in a new tab/windows or opened in internet explorer thus practically pulling users from my app. is there any way to handle the link event to either force the links to open in current view or a way to run code to create a new tab within my own app. i have had a look around and can't seem to see much in the way of a defined way of doing this.
You can hook up to the WebViews "NavigationStarting" event.
The you can cancel the navigation and reissue it from within your code so it navigates inside the webview.
Xaml:
<WebView NavigationStarting="WebView_NavigationStarting" />
Codebehind:
private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
if (args.Uri != null)
{
args.Cancel = true;
sender.Navigate(args.Uri);
}
}
But you will loose the ability to open links in new windows completely, as you only have the uri itself available in the event handler.
Uri will be null if you use the NavigateToString operations on the webview.
This question may be possible duplicate of
WP8 back button go two steps back
My game page structure as follow
MainPage(Select New Game) - > Level1 Page(After complete 60 sec this page automatically goto next page->Alert page (it contain TryAgain-Home-Exit Buttons if user click TryAgain Button "Level1" Page Show)
My problem start here..
Now User in "Level1" user click phone back button it show the Alert Page . it's wrong
but correct way is from "Level1" to MainPage
I try following code in Level1 Page
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
RootFrame.RemoveBackEntry();
base.OnBackKeyPress(e);
}
I got error in RootFrame The name 'RootFrame' does not exist in the current context
Any one tell me where i made mistake and what code i need to add for RootFrame. this is my first Wp8 game app development. Thank You
I just had this same problem. The tutorial uses RootFrame.RemoveBackEntry();
The default is NavigationService.RemoveBackEntry();
I'm creating a Windows Phone 8 app, but I'm stuck at the last part...
It's an app to view the calendars on school: see calendar
Now I open the link of every class (I have the changes for every class, but it opens small... What can I do to solve this ? (See picture) + I can't acces the website codes.
See the picture:
I only want the calendar of the website and not the rest at the left side.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Body.Style = "zoom:300%;";
}
assuming webBrowser1 is the name of your control
I made a small app, and I have a button than pin to start a web blog via a xaml, so when the tile is pin, it goes to the xaml, which automatically redirect to the blog by WebBrowserTask. MY problem is that if they press the back button from the web page, they go to the xaml, and I want them to go directly to the start menu, so I'm looking for a way to kill the app when they return from the
the xaml code is
private void WebPages_Loaded(object sender, RoutedEventArgs e)
{
try
{
WebBrowserTask task = new WebBrowserTask();
task.Uri = new Uri(NavigationContext.QueryString["uri"]);
task.Show();
}
catch (KeyNotFoundException)
{
MessageBox.Show("No URI was passed to the app.");
}
}
I don't know if this is possible, but if someone knows i'll be pleased. Thanks
Try this : Windows Phone 7 close application to kill an app, you may want to try this solution :
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
You may want to load your blog inside a WebBrowser control rather than running a WebBrowseTask. Then, clear the back stack if need be in the OnBackKeyPress event. If you open a WebBrowserTask, the user will have to hit back to resume your app and then hit back again to return to the start menu. You won't be able to exit your app automatically after resuming. Its against the marketplace guidelines.