Introducing Coding4Fun toolkit for Windows Phone 7 - Part 1

DZone 's Guide to

Introducing Coding4Fun toolkit for Windows Phone 7 - Part 1

· Mobile Zone ·
Free Resource

As a side project, Coding4Fun released a toolkit for Windows Phone 7 developers. It is a set of extensions (just like the Silverlight Toolkit for Windows Phone 7) - a number of controls and utilities that can make the development process easier and in some cases save the developer extra hours of work on custom controls.

In this article I am going to talk about the AboutPrompt, which is a popup that has pre-defined fields to display information about the application and its developer. If you start working with it right from Visual Studio, you will see that since it inherits from PopUp and that inherits from Control, there will be a multitude options that will be confusing at first and it will be hard to understand what exactly can be used. You can look at the documentation page to see what properties are exposed, and you can look at the class through Reflector:

Body, Footer, Title, VersionNumber and WaterMark are the properties that set the information that will be displayed in the AboutPrompt. It is not tied to text fields only and it is highly customizable. If you follow the default pattern, there is a Show method that has three overloads:

The default Show call will show the AboutPrompt instance with the manually set properties - you would have to explicitly declare the values. For example:

AboutPrompt prompt = new AboutPrompt();
prompt.Title = "About my app";
prompt.Body = "Hello! This is the information related to my application.";
prompt.VersionNumber = "Ultimate";

Here is how the result looks like:

There is one problem with this image - the about string is cut-off and this is not exactly something that is desirable. What is possible to do is using string escapes to split the lines via \n:

prompt.Body = "Hello! This is the \ninformation related to my application.";

The result looks much better now:

It's still somewhat of a pain to fix strings like this and after all developers probably want to include some custom formatted data. This is where the Body property comes out. In fact, it is not a string but rather an object. Therefore, it can carry custom UI elements. For example, let's say that I want to have a custom button in the popup that will open the web browser and send me to the developer blog. It can be done like this:

private void button1_Click(object sender, RoutedEventArgs e)
Button b = new Button();
b.Height = 100;
b.Width = 100;
b.Content = "Go!";
b.Click += new RoutedEventHandler(b_Click);

AboutPrompt prompt = new AboutPrompt();
prompt.Title = "About my app";
prompt.Body = b;
prompt.VersionNumber = "Ultimate";


void b_Click(object sender, RoutedEventArgs e)
WebBrowserTask task = new WebBrowserTask();
task.URL = "http://dennisdel.com";

Here is what I have:

The solution the problem with splitting lines in this case would be using a TextBlock control and wrap the contents:

TextBlock t = new TextBlock();
t.Text = "This is an informational dialog that shows some information about my application.";
t.TextWrapping = TextWrapping.Wrap;

AboutPrompt prompt = new AboutPrompt();
prompt.Title = "About my app";
prompt.Body = t;
prompt.VersionNumber = "Ultimate";

The text will be automatically wrapped and you won't have to separate the lines in case you want to display the prompt with some plain text info.

The second overload for the Show method takes an array of AboutPersonItem - a collection of instances that describe the people involved in the application development and maintenance (or, you can include any person you want here). Once again, I used Reflector to look at the properties I can set since AboutPersonItem also inherits from Control and there is a lot of noise in IntelliSense.

Obviously, WebSiteDisplay is a protected internal property, so I should exclude it from the list of properties I can set from my app. It is used to format URLs in a correct way. And by the way, if you are using a Twitter URL (e.g. http://twitter.com/DennisCode), it will store the string with the @ profile pointer. I'll show this in a minute. I created a test array to include two persons:

AboutPersonItem[] people = new AboutPersonItem[2];
people[0] = new AboutPersonItem() { AuthorName = "Dennis", EmailAddress = "someemail@service.dom", Role = "Lead", WebSiteUrl = "http://dennisdel.com" };
people[1] = new AboutPersonItem() { AuthorName = "SomeoneElse", EmailAddress = "someemail2@service.dom", Role = "Assistant", WebSiteUrl = "http://www.twitter.com/DennisCode" };

Once you call Show with this array passed to it, the Body property will be overriden and you won't be able to modify it internally.

The page now looks like this:

Notice how the Twitter URL is formatted - once you tap on the website or Twitter profile pointer, it will automatically launch a new WebBrowserTask that will open Internet Explorer with the URL specified. Tapping on an email will launch an EmailComposeTask instance.

If there is only one app author, you can simplify the process and simply call the last (third) overload for the Show method, like this:

prompt.Show("Dennis", "DennisCode", "someemail@service.dom", "dennisdel.com");

Here you can explicitly declare your Twitter handle and it will use it to navigate to your stream. It is important to mention that all parameters (other than the name) are optional, so, for example, if the developer doesn't have a Twitter username, it can be skipped.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}