Canceling InputPrompt calls BackKeypress

Jan 31, 2012 at 6:27 AM

Here is my issue ... when an input prompt is called but then cancelled with the back key, the backkeypress event on the calling page is triggered, though the page doesn't actually close. This is an issue for me because my backkeypress handler unsubscribes from a global event handler handling internet functions since it's expecting the page  is closing - but it doesn't so now it's no longer listening. It tried setting a variable in my inputbox_completed event if the box was null/cancelled so I can handle it properly in backkeypress, however backkeypress is called before the inputbox_completed. Does anyone have a possible solution?

Jan 31, 2012 at 7:06 AM

have the prompt be a more global var.  do something like this, code isn't exact as I'm winging it off memory.

// page's override for back key

if(myPrompt != null && myPrompt.IsOpen())

//do my work
Jan 31, 2012 at 2:00 PM

I tried declaring it globally in my app class like I did with my network class but get a nullreferenceexception on the declaration:

public static InputPrompt myPrompt=new InputPrompt();

I'm new to C#, I'm probably overlooking something obvious

Feb 2, 2012 at 6:40 AM
Edited Feb 2, 2012 at 6:42 AM

try something like this on the page:

* note: this code is not tested, it was written without compiling it, it shows the concept of what you need to do.

MessagePrompt _prompt;

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
	if (_prompt != null && _prompt.IsOpen)

	// do my work

private void MyMethodToCallPrompt()
	_prompt = new MessagePrompt
			        IsCancelVisible = true,
			        Title = "Test Title",
			        Message = "back button test override."
	_prompt.Completed += prompt_Completed;

void prompt_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
	// do my work
Feb 3, 2012 at 4:56 PM

Thanks, working now ... I knew I wasn't doing it quite right

Jan 26, 2013 at 2:14 AM

Hi! i have found this really useful but im having trobules with an Exception at the moment i try to back button the prompt.. the appbar goes find, but when i try to press the button again, i get Element is already the child of another element Exception an Invalid Operation Exception.. i tried with the code you showed up there but it keeps giving me the same problem.

Jan 26, 2013 at 6:58 PM

Shaka77, would have to see more what is going on, any chance you could create a ticket with a repo project so I could dig around?

Also the new version of the kit which i'm about ready to release *should* have a lot of fixes for edge cases like this scenario.