For those of you that have used the Input Prompt or rather not have to use a third party reference to make a pop up alert, I have just the project for today’s lesson for you. Let’s say you would like to create an Alert window in which you have to encapsulate a number of additional controls, well you can.

Before we get carried away, let’s go ahead and jump right in and see what we can come up with. Let’s create a new project for this example. Once done so we are ready to get our hands dirty.

In the ContentPanel section in our XAML file, we can go ahead and add a Rectangle control, which we will use as a container for our controls. Be sure to name the control as well as set the Visibility to Collapsed. We will then add a Border control to add a bit of styling and set the Alignment to Center.

We will also be setting the Brush and Background to the Static Resource. With the Border control you have the option of only adding one control within it, but we have a way to work around that.

We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!

Code Block
MainPage.xaml
Rectangle and Border Control
<Rectangle Name="disableRect"
            Fill="#80000000"
            Visibility="Collapsed"/>
<Border Name="formatDialog"
        Background="{StaticResource PhoneChromeBrush}"
        BorderBrush="{StaticResource PhoneForegroundBrush}"
        BorderThickness="3"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Visibility="Collapsed">
</Border>
What we will do now is add a Grid control inside of our Border control, which we can place additional controls in. We will have two rows and two columns.
Code Block
MainPage.xaml
Grid Control within Border Control
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="258" />
        <ColumnDefinition Width="154" />
    </Grid.ColumnDefinitions></Grid>
In the (0,0) location of our Grid control we will now go ahead and place a StackPanel control. Inside this StackPanel we will be using this to organize our Radio Button controls that we will be using for this to demonstrate the versatility and amount of controls that can be used within our DIY Alert.
Code Block
MainPage.xaml
StackPanel within Grid Control
<StackPanel Name="radioButtonPanel"
            Grid.Row="0"
            Grid.Column="0"
            HorizontalAlignment="Center">

    <RadioButton Content="I like Football."
                    Tag="I like Football."/>

    <RadioButton Content="I like Video Games."
                    Tag="I like Video Games."/>

    <RadioButton Content="I like to Develop."
                    Tag="I like to Develop." Height="74" Width="290" />
</StackPanel>
Once we have that taken care of we can move to the (1,0) and (1,1) locations in which we will be placing a Button control in each for Confirmation or to Cancel, respectively. We will also add the Click events for these two Buttons as well.

We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Code Block
MainPage.xaml
Confirmation and Cancel Buttons in Alert Window
<Button Grid.Row="1" Grid.Column="0"
        Content="ok"
        Click="OnOkButtonClick" />

<Button Grid.Row="1" Grid.Column="1"
        Content="cancel"
        Click="OnCancelButtonClick" />
And this will be all we have in our Alert. To Initiate the Alert we will be using a Button control in our Main Content Grid and create a Click event as well.
Code Block
MainPage.xaml
Button Control in Main Content for Alert Window Event
<Button Content="Click Me!" Height="72" HorizontalAlignment="Left" Margin="120,491,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
Moving along to our Code Behind we will now be taking care of our OnClick events for our three Button controls; two in the Alert and one in our Main Content.

For our Main Content Button we will be setting the Rectangle control, as well as our Border control Visibility equal to Visible.
Code Block
MainPage.xaml.cs
Alert Window Event
private void button1_Click(object sender, RoutedEventArgs e)
{
    disableRect.Visibility = System.Windows.Visibility.Visible;
    formatDialog.Visibility = System.Windows.Visibility.Visible;
}
For our Cancel Button control we will be returning our Border and Rectangle controls back to their Visibility equal to Collapsed.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Code Block
MainPage.xaml.cs
Cancel Button Event
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
{
    disableRect.Visibility = Visibility.Collapsed;
    formatDialog.Visibility = System.Windows.Visibility.Collapsed;
}
Last but not least, on our Confirmation Button control we will be displaying a simple MessageBox with some text to display to visualize that the event has taken place. But we are not done. This will not collapse our Alert, so what we can do instead of repeating the same code we wrote for our Cancel event is call the Cancel OnClick event.
Code Block
MainPage.xaml.cs
Confirmation Button Event
private void OnOkButtonClick(object sender, RoutedEventArgs e)
{
    MessageBox.Show(" You Clicked OK.");
    OnCancelButtonClick(sender, e);
}
And there you have it, a simple Alert Window without the need for third party references or toolkits, and the ability to customize it to your very own liking. If you have any other questions or concerns and have not yet downloaded the source code for this project, I strongly suggest doing so. Seeing it in its entirety can help clear up many of your questions. Thank you for your time and I hope this has been helpful, take care.

I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.

WP7PopUpTut.zip