Windows Phone 7 sample About Page

Creating an About Page for our apps is probably one of the last things we do as developers. Although it is not required by Microsoft for an app’s acceptance into the Windows Phone Marketplace an About Page is a good idea as it allows you to house all the information someone downloading an app looks for. In this post I will show you my sample About Page that I have used on many of my apps and provide you with the code to download so you can add it to your apps quickly and easily.

When I build apps I favour the Pivot Application template. I find that it allows users to navigate around my app effortlessly. As such my About Page example will be for a Pivot application but with minor modifications this code could be added to any WP7 app.

This is the Pivot Item code for my MainPage.xaml Pivot Control:

Windows Phone 7 About Page Xaml

To use the code as is you only need to input your app’s title and your name at the bottom where you declare your copyright. You can also modify this code if you wish to move items around or change your ownership declaration.

And here is the code behind:

Windows Phone 7 About Page Code Behind

And here are the using statements:

Windows Phone 7 About Page Usings

 

To use the code behind from the example you will need to add both the Microsoft.Phone.Tasks and the System.Reflection namespaces.

As you can see the help button generates an email to an email address of your choice. This method needs you to only set your email address and your application title in the subject line of the method. The method pulls the current major and minor version numbers out of the Assembly property in the AssemblyInfo.cs file.

If you wish to use the version number in the WMAppManifest.xml instead you need to add a reference to “System.Xml.Linq” in your project references and then add the following using statement: “using System.Xml.Linq;”. From there you can draw the version number out with the following piece of code:
string Version = XDocument.Load(“WMAppManifest.xml”).Root.Element(“App”).Attribute(“Version”).Value;

You will want to provide a support link as it allows users to notify you if there is a problem. They will also email you to helpfully suggest improvements to your app so that their experience will be better. It is like giving your app to a focus group!

Both the MarketplaceReviewTask and MarketplaceSearchTask use the Microsoft.Phone.Tasks namespace. Through this reference users can both rate your current app and also search for your other apps. For additional information on this namespace check out this link. There are many more classes that you can tap into with this namespace.

Allowing users to rate and review your app from the About Page is a great idea as they can do it while they are thinking of it. Their ratings will then increase your standing in the Marketplace and in the developer community as you are seen as someone who develops quality applications.

Windows Phone 7 About PageAs you can see from the finished product on the left that creating a functional About Page is a pretty easy task and it provides a benefit to both the user and yourself.

You can download the code from this article here and from my GitHub account.

Use Ctrl + Period to resolve a missing namespace reference

I love Microsoft Intellisense and the fact that it is so helpful. One aspect I like is that it will help you resolve a missing namespace reference. Generally when you add a reference to a namespace and it has not been declared, Microsoft will underline the missing reference in red. When you hover over it you will get an error message saying : “The type or namespace name ‘xxx’ could not be found (are you missing a using directive or an assembly reference?)

 missing reference

 

 

To resolve this problem you have two options, you can right-click the missing reference and choose Resolve.

missing ref 2

You can place a reference to the missing namespace at the top of your class by choosing the using statement or you can place it inline by selecting the full namespace. If you are going to be using this namespace reference in other places within your class then obviously the former is the better choice.

There is another way to create a reference to this missing namespace. When you know the namespace is missing and you have finished typing the initial reference, you can hit Ctrl + . (period) to raise a dialog box helper. From here you can arrow up or down to select and instantiate the namespace reference. This way you do not have to reach for the mouse and break your flow.

missing ref 3

Using Statements to wrap your database connections

In yesterday’s piece entitled Using Regular Expressions (Regex) to find all your SqlConnection strings I wrote about the fact I was trying to use  a regex string to find all my SqlConnection declarations.

In the piece I made mention of the fact that the using statement are becoming the defacto way of wrapping your connections. I first heard about this in the James Michael Hare series of articles C#/.NET Little Wonders – All The Wonders In Their Glory

The using statement is not the same as the using declarations at the top of your code behind files. Instead, they are used to wrap pieces of code so that they will call IDisposable as soon as they go out of scope.

So, instead of forgetting to call dispose on your SqlConnection instances and running the chance of having some connection pooling issues, we can use the following to instantiate our objects:

using statement

As you can see I have wrapped the code in a using block with both brackets and curly braces. I don’t have to use any try/catch statements nor do I have to explicitly dispose of my connection object. The using statement will call the Dispose() method as soon as it is out of scope – either when it completes or if it encounters an error.

So, check out using statements. They will make sure you never have to worry about closing out your connection strings and they will make your code a little bit neater.

Using Regular Expressions (Regex) to find all your SqlConnection strings

I was looking through some inherited code and there were some connection strings spread out throughout the project. Now because I try to make sure everything is closed in good order I needed a way to find where each was declared. I could change them all to using Statements but that just seems like a lot of work.

Instead, I found this nifty little piece of regex syntax that allows you to search through your connection strings:

new:Zs*(System.)*(Data.)*(SqlClient.)*SqlConnection(\([0-9a-zA-Z]*\))

In Visual Studio 2010 hit Ctrl+F and place the string in the Find what: textbox of the Find and Replace dialog box. Make sure to click the Use checkbox at the bottom and select Regular expressions. Also, make sure there are no trailing spaces after the last bracket or else it will not work. Click Find Next and voila. The nice thing about this is that it will find them if they are declared explicitly or not.

Find SQlConnection string with regex

Follow

Get every new post delivered to your Inbox.