Getting MessagePrompt to close when tapping outside its area

Mar 20, 2013 at 12:07 AM
Hi, I have a MessagePrompt that brings up a little popup for users to share stuff, but I want it to close if the user taps anywhere outside said popup, instead of having a cancel/close button. Is there any way to do this?
Coordinator
Mar 20, 2013 at 12:12 AM
Call the myPrompt.Hide() method on the Prompt. Also if you don't want any buttons to show, myPrompt.ActionPopUpButtons.Clear();
  • Assumption in code above is the MessagePrompt you created is named myPrompt
Mar 20, 2013 at 12:15 AM
Alright, but on what event is the Hide() method called? I've tried playing with the OnLostFocus event, but no dice.
Coordinator
Mar 20, 2013 at 12:30 AM
I misread what you wanted. Prompts like this are designed to act like a system level one. The end user either takes action or dismiss the prompt with the back button.Someone could easily touch an area and your dialog goes away. View the mail app when you "reply, reply all, forward". If you tap anywhere above that, the overlay prevents you from opening up another email.

I strongly think what you want is a bad idea. It is 100% possible however. Here is functional code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    var msg = new MessagePrompt();
    msg.IsOverlayApplied = false;
    msg.ActionPopUpButtons.Clear();

    msg.Title = "hello";
    msg.Body = "world";
    msg.Show();
    msg.LostFocus += msg_LostFocus;
}

void msg_LostFocus(object sender, RoutedEventArgs e)
{
    var msgPrompt = sender as MessagePrompt;

    if(msgPrompt != null)
        msgPrompt.Hide();
}
Mar 20, 2013 at 12:45 AM
Thanks so much, I realize it's not exactly a great idea to do it this way, but in this instance, it's out of my hands.