While certifiying my Phonegap App for Windows Phone 7 I was told that the back-button doesn't work the way it should. My application only has one page, so here it's not a problem but it is possible to display a menu using javascript.
When this menu is open, the back-button is supposed to close the menu instead of exiting the application. Does anyone have an idea on how I could easily catch the event of a click on the back-button in order to check if the menu is open and then close it or completely exit the application if it isn't?
I tried document.addEventListener("backbutton", onBackKeyDown, false); but apparently this does not work for Windows Phone 7!
Thanks a lot
WP7 PhoneGap definitely supports the back button. You can download a working example from my blog here:
http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/
Make sure you handle the deviceready event first.
Why don't you use the native Silverlight.
XMAL
BackKeyPress="PageBackKeyPress"
Code-Behind
private void PageBackKeyPress(object sender, CancelEventArgs e)
{
// DO NOT CLOSE
if (Something)
e.Cancel = true;
}
I have the same problem. When you write
document.addEventListener("backbutton", onBackKeyDown, false);
That will block the the default backbutton handler. So you may need to do so tricks in the phonegap code. It's not the best way, but it's quite easy though. Check out this one:
http://blog.projectdebug.com/?p=6
Related
in my XF application I have the possibility to open a web page.
For do this I use the Xamarin.Essential: await Browser.OpenAsync(url, opts);.
I need to have a callback when the user tap on Done button (on iOS) or the back button (on Andorid).
How can I do this?
There is another way other than use Xamarin.Essential?
Thank you!
EDIT
I need to execute some C# code when the user tap on the "done button" in iOS or the back button on Android when the WebView is open.
I'm not trying to execute some JavaScript code, or execute C# code from Javascript.
Android video.
Sample here.
Yeah if you don't want to use Essentials for opening pages, you could use
Device.OpenUri(new Uri("www.example.com"));
And if you want it to be in a async fucntion
await Device.OpenUri(new Uri("www.example.com"));
And if you are looking into adding callback functionality from the webview, you would need to create a HybridWebView and custom renderers for iOS & Android, as shown here.
I want to detect swipe in web browser control in C# using JavaScript. I want to add some JavaScript to my web content and then if swipe occurs, call a method that loads another web content in the same web browser control.
I would like some sample code or any other suggestion to do this.
Thanks in advance
You'll need to use something to detect the swipe in javascript. I've been recommended to use touch.js but haven't had a chance to try this yet.
When you detect the swipe you can call out to native code using window.external.notify().
Be sure to set IsScriptEnabled="True" on the WebBrowser control and register an handler for the ScriptNotify event.
It's this event handler which would load the new content.
First of all, consider that gestures for a webbrowser control have it's own handlers. Now, if you don't need to pan/zoom or the like in the webbrowser control, it's not a problem.
Then you simply set the IsHitTestEnabled attribute to false, so that the web-browser no longer receives input. Then you can simply use the GestureService from the Silverlight Toolkit to handle the swipe/flick inputs.
I wrote some code on how to handle this, in another question: wp7 horizontal swipe selection
I have an application that uses the web browser control to show local content on a device, this is hosted as a page in the application, it integrates well with the physical back button.
The issue I have is if I place a button in the application bar to exit the web browser and go back to the page previous to the web browser page then the WP7 application page stack remembers this and if I start pressing the back button it will go to web browser page and start traversing the pages (in reverse) I have viewed in the browser.
Ideally what I want is the web browser page to not be included in the application page stack, can I modify the contents of the stack at runtime or force a page not to be included?
Jaime article describes the usage situation for the browser control.
http://blogs.msdn.com/b/jaimer/archive/2011/02/04/back-button-press-when-using-webbrowser-control-in-wp7.aspx
Generally it is not possible to modify the NavigationStack in Windows Phone 7.0 SDK. In Mango (7.1) you will be able to Clear your NavigationStack.
NavigationService.RemoveBackEntry();
Jesse Liberty has a very good article on this:
http://jesseliberty.com/2011/05/24/managing-the-back-stack/
The linked article shows how to add pages navigated to in the webbrowser to the back stack.
By default the navigation history of the WebBrowser control is not included in the application back stack.
It sounds as though you've added extra behaviour (to include the browser history in the page back stack) and now you want to work around it.
At first, thanks to valipour for the link provided! This solution is great, but I just want to add that in order to clear all the navigation stack you need to do the following:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.New
&& NavigationContext.QueryString.ContainsKey("clear"))
{
while (NavigationService.CanGoBack)
{
NavigationService.RemoveBackEntry();
}
}
}
If you add this code to the MainPage.xaml code-behind and launch it with /MainPage.xaml?clear=true URI, the navigation stack will be cleared.
I've seen applications on WP7 that seem to use a control that dims the app, plays a quick sound, and shows a dialog at the top of the screen. What is this control called as I cannot seem to find it anywhere.
Try MessageBox.Show
MessageBox.Show("Hello world!");
Here is a more flexible version of MessageBox
Has anyone implemented Tap & Hold in a Windows Phone 7 App yet? I can see a couple of possible approaches KeyDown/KeyUp and a timer or ManipulationStarted/manipulationCompleted and a timer.
However it strikes me that this is a less than idea approach because different apps would have different timer settings leading to inconsistency.
Am I missing something? I was hoping for a TapAndHold event
For all views Hold method is there.
It will handle long press function.
Silverlight Toolkit for Windows Phone adds easy to use gestures support, including On Hold gestures
I'm in the same situation, and I'm looking for "the recommended way". In the meantime, Mike Francis posted a solution on his blog, using Microsoft.Xna.Framework.Input.TouchPanel's gesture recognition within a Silverlight app. I didn't try it.
Start the Timer on Hold Event of GestureLister
and stop it on GestureCompleted event this is really a trick see detail answer on following link
How do I detect when toolkit:GestureListener Hold has stopped?
Button b = new Button();
b.Hold += new EventHandler<System.Windows.Input.GestureEventArgs>(HoldEventHandler);
The above code should work for touch and hold event