A C# beginner but want to target Android and iOS? Share the same code across all platforms

A C# beginner but want to target Android and iOS? Xamarin is the solution for you!

If you are new to mobile application development, you might be confused about how one programming language can be used to develop applications for multiple platforms when you learnt that app development for the three major platforms requires three different languages. Well that’s true but here’s how it works.

Continue reading


LocalSettings to store data in Windows Store and Windows Phone WinRT applications

If you are developing a windows 8.1 store app or a windows phone 8.1 WinRT application and you need to store some data in a memory space reserved for your application, you will use ApplicationDataContainer namespace’s LocalSettings – the newer unified Windows Store app API. This API also works with Silverlight applications along with IsolatedStorage. But IsolatedStorage does not work with WinRT applications. Hence, if you plan to migrate your apps to WinRT at a later stage, you might want to consider using this.

You can store small pieces of data, other application related settings or even information sensitive to the app in the LocalSettings. It is generally used to Continue reading

Isolated Storage Settings in Windows Phone

Note: This post will be helpful if you are creating a Silverlight application. If you are creating a WinRT application and you need to store and retrieve files, you will use LocalSettings. For that, visit here.

IsolatedStorage is a ‘memory’ space local to your application and is reserved for your application when you install an app on your Windows phone device. You can store small pieces of data, other application related settings or even information sensitive to the app in the IsolatedStorage. It is generally used to store app settings when the app loads or exits. The stored data cannot be accessed by other applications. It remains Continue reading

Passing multiple parameters with page navigation in windows phone 8/8.1

One of the most basic feature all apps mostly have is navigating to another page, which in itself is mostly required by any quality app. As soon as our app launches, its on the main page. It takes a single statement to navigate and work on another target page whether its a windows phone 8/8.1 app. If you are developing for windows phone 8, here’s what you need to do:

NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

With windows phone 8 being a history now. Here’s how you can navigate on windows phone 8.1:


Passing a parameter:

If you want to send some data from one page to another, you can send your variable as a parameter with the navigation statement. You will do this as below:

string name = "abc";
Frame.Navigate(typeof(SecondPage), name);

Now on the target page, you can retrieve this parameter data in the OnNavigatedTo() function as follows:

protected override void OnNavigatedTo(NavigationEventArgs e)
      string myData= e.Parameter.ToString();

Passing multiple parameters:

One of the common mistake people do or assume that it can work is passing the parameters the same way as passing a single parameter. Following code DOES NOT work:

string name = "abc";
string email = "abc@hotmail.com";
Frame.Navigate(typeof(SecondPage), name, email);

To pass multiple parameters to a target page using the navigate statement, I will mention three approaches below:.

  1. You can set global variables at application level and use wherever you want. But this is not a good approach and you really don’t want to mess alot of things and make it complicated.
  2. You can also store your variables in IsolatedStorageSettings and retrieve them on the target page. Here’s how to use ISolatedStorageSettings in your application.
  3. Third and one of the best approach is to create a custom class, set your parameters in it and send its object as a parameter to your target page.

For example. Your custom class:

public class CustomDataClass
public string name;
public string email;

CustomDataClass myData = new CustomDataClass();
myData.name = "abc";
myData.email = "abc@hotmail.com";

Frame.Navigate(typeof(SecondPage), myData);

And then on the target page you can retrieve in OnNavigatedTo function like this:

protected override void OnNavigatedTo(NavigationEventArgs e)
CustomDataClass myData2 = e.Parameter as CustomDataClass;
string name = myData2.name;
string email = myData2.email;

And that’s it. Just a few simple steps for easy and clean passing of data between your pages. Hope it helps!

App Rating Reminder for ‘Windows Store’ apps

My older post is about the app rating reminder for windows phone. For Windows 8, it is similar only with little difference, so to clear it out, here is the code. The concept is that we will display a reminder every 3 times the application is launched until the user rates the app.You can write the code below in the page_loaded event as below:

private async void Page_Loaded(object sender, RoutedEventArgs e)

var settings = Windows.Storage.ApplicationData.Current.LocalSettings;
if (!settings.Values.ContainsKey("WasLaunched"))
Windows.Storage.ApplicationData.Current.LocalSettings.Values["ratingDone"] = "False";
settings.Values.Add("WasLaunched", true);
Windows.Storage.ApplicationData.Current.LocalSettings.Values["Count"] = 1;
var c = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Count"];
int count = Convert.ToInt32(c);
Windows.Storage.ApplicationData.Current.LocalSettings.Values["Count"] = count;

if (Windows.Storage.ApplicationData.Current.LocalSettings.Values["ratingDone"].ToString() == "False")
if (count % 3 == 0)
MessageDialog msgDialog = new MessageDialog("Please rate the application", "App rating");

//OK Button
UICommand okBtn = new UICommand("OK");
okBtn.Invoked = OkBtnClick;

//Cancel Button
UICommand cancelBtn = new UICommand("Cancel");
cancelBtn.Invoked = CancelBtnClick;

//Show message


Now the methods for Ok and Cancel button:

private void CancelBtnClick(IUICommand command)
// nothing shall happen if we cancel

private async void OkBtnClick(IUICommand command)
Windows.Storage.ApplicationData.Current.LocalSettings.Values["ratingDone"] = "true";
await Launcher.LaunchUriAsync(new Uri(String.Format("ms-windows-store:REVIEW?PFN={0}", Windows.ApplicationModel.Package.Current.Id.FamilyName)));


In the OkBtn event, we are storing the package name of our application, While testing, it will lead to the store rating page but display an error message that App is no longer available. It will be shown once the app is on store.


Launch another app from within your app

If you want to open a url directly in your browser from within your windows phone 8/windows 8 app, you can use the following code in an async event.

await Launcher.LaunchUriAsync(new Uri(“http://en.wikipedia.org/wiki/UAE”));

This statement will open the ‘UAE’ search term page in Wikipedia website in your browser.

Now, if you want to open Wikipedia app installed in your phone, add the following code in your async event:

await Windows.System.Launcher.LaunchUriAsync(new System.Uri(“wikipedia://”+”UAE”));

This will prompt the user to first install Wikipedia app on windows phone 8 if not installed and then navigates to a page showing ‘UAE’ search term result.

Handling the MediaElement on already playing music on phone

When ever you use the Media Element in Windows phone, you shall prompt the user to stop/pause if any music is already being played on the phone. If the user selects OK, the phone music stops/pauses and the media in your app plays. However, if you do not use this, your app can fail the certification according to criteria 6.5. For handling this, you can add the following code. In this code, I assume we have a play button. Clicking on it shall first prompt the user for consent and then play my media when user clicks OK.

private void PlayButton_Click(object sender, RoutedEventArgs e )



if(Microsoft.XNA.Framework.Media.MediaPlayer.State == MediaState.Playing)

if(MessageBox.Show(“Do you want to stop your music and enable the app music?”, “Can play app music?”,    MessageBoxButton.OKCancel)== MessageBoxResult.OK)










AudioPlayer is the name of the MediaElement used

App rating reminder using application settings in windows phone 8 app

To increase the ratings of your windows phone 8 app and to add a feature of a quality app, use app rating reminder. In this post, I will add the code that reminds the user every third time he/she user the app until the user rates it.

Add this code to your Mainpage as it executes when the app is launched and LayoutRoot is loaded

Add using Windows.Phone.System.UserProfile; to the top and then add the following method

private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)

int count = 0;

var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains(“WasLaunched”))
IsolatedStorageSettings.ApplicationSettings[“ratingDone”] = “false”;
settings.Add(“WasLaunched”, true);



if(IsolatedStorageSettings.ApplicationSettings[“ratingDone”].ToString() == “false”)

if (count % 3 == 0)
MessageBoxResult result =MessageBox.Show(“Please rate and review the app to make it better?”, “MessageBox Example”, MessageBoxButton.OKCancel);

if (result == MessageBoxResult.OK)
IsolatedStorageSettings.ApplicationSettings[“ratingDone”] = “true”;
MarketplaceReviewTask marketplaceReviewTask = new                                                     MarketplaceReviewTask();





Create apps for a new generation

Are you interested in developing windows store apps? This post will guide you to the right developer tools, tutorials and resources. There are 3 steps to build your windows store apps:

  • Get the tools
  • Build and test the app
  • Publish the app

1. Get your development tools:

Windows 8/8.1

You would need: Windows 8/Windows 8.1,visual studio 2012/2013, Windows 8 SDK and the developer license. You can get Windows 8 from Dreamspark Premium subscription of your school Webstore. To find a link to your webstore, goto http://aka.ms/w8gsg28 and enter your school name in the 3rd search box.

You can also visit http://aka.ms/w8gsg01 for more details.

Visual Studio 2012/2013

You need to download and install visual studio 2012 for windows 8 and visual studio 2013 for windows 8.1. You can do this using dreamspark (if you are a student) at no cost at all.


You would need:

  • Windows 8 Software Development Kit
  • Blend for Visual Studio to create and edit images, and design your apps
  • Windows App Certification Kit (WACK) to test your apps

These are the collection of tools and software that you need to design, create, debug, package and publish your Windows 8/8.1 apps to store.

Software Developer License:

When you install Visual Studio Express, you will be asked for a developer license. For that, you would need a Microsoft (Hotmail) account.

2. Build and test the app

Choose a programming language:

You can build a Windows store app using the following programming languages. You can select you own choice and start developing:

  • HTML/Javascript
  • XAML/C#
  • XAML/Visual Basic
  • C++/CX

Get hands-on help

Microsoft provides hands on lab to help you learn and  start developing your applications. The hands on labs are available in HTML/Javascript or XAML/C#. You can download the lab from: http://aka.ms/w8gsg05.

Code samples:

The following is a helpful review that covers everything from setting up an app to learning tools and templates: http://aka.ms/w8gsg06

You can download many code samples(covers most topics) to learn from: http://aka.ms/w8gsg07

3. Test Your app:

Before submitting your app, test it. The Windows App Certification KIT (WACK) that you downloaded earlier is used for this. For testing, goto windows start screen -> run WACK app -> Select your custom app -> select next.

Submit your app:

To submit your app package to the store, create the app package by going to store menu in visual studio -> create app packages. You will need Microsoft account to submit apps to your Windows Store.

In the store:

When you submit an app to the store, you need to have an app name, price for your app (or free), age rating, a description of your app and screen shots. Once you publish your app, it wil go through a certification process and you will receive an email once its passed and published to the store.

Useful resources:

Some resources that can be useful for development of windows store apps: