MessagePrompt

Overview

Basically MessagePrompt is an UI component that derives from the toolkit`s UserPrompt class . As its name says it is a kind of extended popup that displays a message. MessagePrompt can display different content like Title, composite Body content, custom buttons, etc .


Getting Started

To begin using MessagePrompt first add a reference to the Coding4Fun.Phone.Controls.dll assembly.

Creating MessagePrompt:

C#:
var messagePrompt = new MessagePrompt
    {
        Title = "Simple Message",
        Message = "This is a demo of the Coding4Fun MessagePrompt."
    };
    messagePrompt.Completed += messagePrompt_Completed;
    messagePrompt.Show();

void messagePrompt_Completed(object sender, PopUpEventArgs<object, PopUpResult> e)
{
     //add some code here
}

Key Features

MessagePrompt exposes the following properties that can be used to customize its content:
  • ActionPopUpButtons
  • Message
  • Title
  • Body
  • Overlay
  • IsAppBarVisible
  • IsCancelVisible
  • HasGesturesDisabled

NOTE: What is the HasGesturesDisabled property? : With the current Gesture Service in the Silverlight Toolkit (Feb 2011 release), if two controls are overlapped and the bottom control has a listener attached, events will still bubble through with no way to cancel it without putting on a listener. In a control that is called PopUp, it is self defeating to have this bubble through effect happening. If the SL toolkit corrects the behavior, we’ll remove the HasGesturesDisabled property as it would no longer be needed. This would also remove the dependency on the Silverlight Toolkit.

You can show MessagePrompt using its Show() method.
When the MessagePrompt popup is closed the Completed event is fired.

Example1:
var messagePrompt = new MessagePrompt
    {
        Title = "Advanced Message",
        Body = new TextBlock { Text = "Bory of the Coding4Fun MessagePrompt.", Foreground = new SolidColorBrush(Colors.Green),FontSize = 30.0, TextWrapping=TextWrapping.Wrap},
        IsAppBarVisible = true,
        IsCancelVisible = true
    };
    messagePrompt.Show();



Example2:
MessagePrompt messagePrompt;
private void btncustomizedMessage_Click(object sender, RoutedEventArgs e)
{
    messagePrompt = new MessagePrompt();
    messagePrompt.Message = "Some Message.";
    Button customButton = new Button() { Content = "Custom Button" };
    customButton.Click += new RoutedEventHandler(customButton_Click);
    messagePrompt.ActionPopUpButtons.Add(customButton);
    messagePrompt.Show();
}
 
void customButton_Click(object sender, RoutedEventArgs e)
{
    messagePrompt.Background = new SolidColorBrush(Colors.Gray);
}




Example3:
Generally the MessagePrompt is designed to be used in code but sometimes users want to put some composite elements into the popup body so in this case it is easy to define these element is XAML. Here is one possible solution with UserControl. Just create a new UserControl named for example BodyUserControl and add the following code into it:

BodyUserControl :
<Border BorderBrush="YellowGreen" BorderThickness="2">
    <StackPanel x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}"  Margin="0,0,0,10">
        <TextBlock Text="Body declared in UserControl XAML" HorizontalAlignment="Center"/>
        <Image Source="AppIcon.png" Height="80" Width="80" HorizontalAlignment="Center"/>
         
        <Border Background="YellowGreen" Height="100" Width="400">
            <TextBlock Text="This is the first text in the Body section. Another Body content here" TextWrapping="Wrap" VerticalAlignment="Center"/>
        </Border>
    </StackPanel>
</Border>

MainPage.xaml.cs
 MessagePrompt messagePrompt = new MessagePrompt();
    messagePrompt.Title = "UserControl test";
    messagePrompt.Body = new BodyUserControl();
    messagePrompt.Show();



Last edited Apr 26, 2011 at 10:32 AM by WinPhoneGeek, version 1

Comments

korbert Wed at 11:30 AM 
I know it's a little late... but you can do this to access same method properties:

msgBox.Completed += ((sender, e) => {
switch (e.Result)
{
default:
break;
}
});
msgBox.Show();

densbucs Jul 12 at 5:07 AM 
Is there an option to add a "Do not ask me again" checkbox?

quoctrung117 Jun 13 at 9:44 AM 
@neerajsaini1982:

if (e.PopUpResult == PopUpResult.Ok) {

var popup = (BodyUserControl)((MessagePrompt)sender).Body;

var listPicker = (ListPicker)popup.FindName("MylistPicker");

var name = listPicker.SelectedItem.ToString();

}

muushfiqq Jun 14, 2012 at 11:23 AM 
please someone can tell me about HorizontalContentAlignment and VerticalContentAlignment ?

neerajsaini1982 Aug 29, 2011 at 6:39 PM 
how to get the value of the textbox in the main page
e.g suppose I created a user control UC1 with a textbox in it. Now on the main page I used it like
messagePrompt.Title = ".?";
messagePrompt.Body = new UC1();
messagePrompt.Completed += new EventHandler<PopUpEventArgs<string, PopUpResult>>(messagePrompt_Completed);
messagePrompt.Show();

void messagePrompt_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
{
how to get the value of the UC1 textbox here?
}