Getting Started With AboutPrompt Control in Windows Phone 7


Introduction

In this step we will explore how to use an AboutPrompt control in Windows Phone 7. In subsequent details we will learn how it is possible to work with such type of control in Windows Phone 7. Here in this article I will explain everything about the main features, available public API, and will provide many examples in various scenarios. Further as we know that basically the AboutPrompt is an UI component that derives from the toolkit`s abstract PopUp<T, TPopUpResult> class. Now it's time to become familiar with it in details which is given further. As its name implies it is a kind of extended popup which prompts for the OK button click. It is the control which is used to display various content like Title, VersionName, WaterMark etc. To use it first you have to download the Coding4Fun toolkit from here and follow the steps which is given below.

Step 1: In this step first of all we have to create a Windows Phone application; let's see how you to create it.

  • Go to Visual Studio 2010
  • File->New->Project
  • Select the template named as Silverlight for Windows Phone
  • Select the Windows Phone application
  • Give it a name as you want.   

Step_1_1fig.gif

Step_1_2fig.gif

Step 2: In this step we will see from where you add the assembly reference which is shown in the figures given below.

Step_2_1fig.jpg

Step_2_2fig.jpg

Step_2_3fig.jpg

Step 3: In this step you will add an namespace to the MainPage.xaml.cs file which is shown below.

Step_3fig.jpg

Step 4: In this step you will see the code for the btn1_click which is shown below used to create AboutPrompt Control programatically.

Code:

private void button1_Click(object sender, RoutedEventArgs e)

{

   AboutPrompt MyABP = new AboutPrompt();

   MyABP.Title = "DefraultText";

   MyABP.Footer = "www.google.com";

   MyABP.VersionNumber = "Version 1.5";

   MyABP.WaterMark = "Shows Watermark String";

   MyABP.Body = new TextBlock { Text = "Inside it we will see the demo of AboutPrompt COntrol in Windows Phone 7", TextWrapping = TextWrapping.Wrap };

   MyABP.Completed += MyABP_Completed;

   MyABP.Show();

}

Step 5: In this step we will see the method code for eventhandler shown below which is given below.

Code:

void MyABP_Completed(object sender, PopUpEventArgs<object, PopUpResult> e)

{

   if (e.PopUpResult == PopUpResult.Ok)

      MessageBox.Show("OK!");

   else if (e.PopUpResult == PopUpResult.Cancelled)

      MessageBox.Show("CANCELLED!");

   else

      MessageBox.Show("meh?");

}

Step 6: In this step we will see the MainPage.xaml file code which is shown below.

Code:

<phone:PhoneApplicationPage

    x:Class="Myapp.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"

    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"

    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>

        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock x:Name="PageTitle" Text="About Prompt" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontFamily="Comic Sans MS">

               <TextBlock.Foreground>

                  <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                     <GradientStop Color="Black" Offset="0" />

                     <GradientStop Color="#FFBEE7E4" Offset="1" />

                  </LinearGradientBrush>

               </TextBlock.Foreground>

            </TextBlock>

        </StackPanel>

        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <Grid.Background>

                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                    <GradientStop Color="Black" Offset="0" />

                    <GradientStop Color="#FF1E99B6" Offset="1" />

                </LinearGradientBrush>

            </Grid.Background>

            <Button Content="Create About Prompt Via Code" Height="77" HorizontalAlignment="Left" Margin="9,82,0,0" Name="button1"

                    VerticalAlignment="Top" Width="420" FontFamily="Comic Sans MS" FontSize="26" Click="button1_Click" />

        </Grid>

    </Grid>

</phone:PhoneApplicationPage>

Step 7: In this step we will see the complete code for the file MAinPAge.xaml.cs file which is shown below.

Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using Microsoft.Phone.Controls;

using Coding4Fun.Phone.Controls;

namespace Myapp

{

    public partial class MainPage : PhoneApplicationPage

    {

        // Constructor

        public MainPage()

        {

            InitializeComponent();

        }

        void MyABP_Completed(object sender, PopUpEventArgs<object, PopUpResult> e)

        {

            if (e.PopUpResult == PopUpResult.Ok)

                MessageBox.Show("OK!");

            else if (e.PopUpResult == PopUpResult.Cancelled)

                MessageBox.Show("CANCELLED!");

            else

                MessageBox.Show("meh?");

        }

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            AboutPrompt MyABP = new AboutPrompt();

            MyABP.Title = "DefraultText";

            MyABP.Footer = "www.google.com";

            MyABP.VersionNumber = "Version 1.5";

            MyABP.WaterMark = "Shows Watermark String";

            MyABP.Body = new TextBlock { Text = "Inside it we will see the demo of AboutPrompt COntrol in Windows Phone 7", TextWrapping = TextWrapping.Wrap };

            MyABP.Completed += MyABP_Completed;

            MyABP.Show();

 

        }

    }

}

Step 8: In this step we will see the design of the MainPage.xaml file which is shown below.

Designimg.jpg

Step 9: In this step we are going to run the application by pressing F5 and the output regarding it is shown below.

Output 1: It's the default output and the figure is shown below.

out1.jpg

Output 2: This output will generate whenever you click on the button.

out2.jpg

Output 3: After click on the right icon then it will ask for OK then click OK and the figure is shown below.

out3.jpg

Here are some other useful resources which may help you.

Getting Started With AdControl in Windows Phone 7
The installed battery may not be properly connected to the computer
Getting URL of current page in Windows Phone dynamically through code
RichTextBox in Windows Phone 7.1 or Mango
Setting The Start Page in Windows Phone 7 Application

Up Next
    Ebook Download
    View all
    Learn
    View all