WeatherView, a C# Universal App Sample


Today's project shows off a simple yet "real" universal application that's already available in the Stores for free, but the source is available too...

WeatherView - a universal Windows app sample written in C#

This is a sample which creates a universal Windows app written in C#, that runs on both Windows 8.1 and Windows Phone 8.1. You can see the app the sample is based on in the Windows Store and the Windows Phone Store.


Windows Store link

Windows Phone store link

What the app does

This app uses geolocation and two web services to create a graphical weather app. First, it uses your location to create a query to send to the Weather Underground web service. This service returns a JSON string, which we parse to extract the current weather, and two forecasts. (Setting up the queries can be a little tricky, which is why I wrote this sample in the first place!)

We take this weather information returned by Weather Underground, and display it: "60 F in Redmond!" - but then more interestingly, we ask Bing for an image to go with it. For example, if the weather forecast is “raining frogs” we ask Bing for some images related to “raining frogs”, and then display that in the background. 

What you need to do first

As this app uses some webservices, you will need to create accounts with them in order to obtain API keys. Without the keys, the app will not function. The good news is that you can obtain these keys for free, although they may time-out, or only operate for a set number of calls per month. If you are going to write a commercial app, you need to carefully consider the terms, conditions and potential costs of using the web services. For experimenting, the free accounts are more than adequate.

Weather Underground account

Azure / Bing Services account

Structure of the app

The app is a universal app, which means it contains both the desktop and the phone projects within the one Visual Studio solution. You can choose which to build by selecting the default start-up project.

Both projects share the same MainPage.xaml and C# code-behind source, and the MainPageViewModel. There are a few cases when some Phone-specific or Desktop-specific code is commented out for compile time. For example, the Phone does not need the SettingsFlyout code.

The app is written following the MVVM design model, and so the XAML file references parameters which are defined in the MainPageViewMode file.

Program flow


[Click through to see the entire post]

WeatherView (

Project Description
A universal Windows app written in C# demonstrating geolocation and webservices.

  • Geolocation
  • Using webservices to obtain weather forecast data,
  • Using Bing/Azure to obtain an image related to a search term
  • Written following MVVM using C#

Here's a snap of the Solution;



As you can see, you share what you can share, you customize for a device where you need, or want, too.

The Discussion

  • User profile image

    I am unable to run the code. Getting the error "1    File 'Package.StoreAssociation.xml' not found."

    Error Images.



  • User profile image

    @itsaboutcode:Best bet to ensure the author sees this would be to post it directly in the CodePlex project, either as a new issue or discussion.

  • User profile image
    John Kennedy

    Oops.. I cleaned up the project to post it safely online. I'll go back and make sure this file is added.
    If you re-add images yourself manually, there's a good chance this file will be re-created.

  • User profile image

    @John Kennedy:Thanks John!

  • User profile image

    @gduncan411: Thanks John. I will do that in future.

  • User profile image

    Ah, I misread this comment at first, and thought it was related to the images in the solution. This file is actually one that is required when you are publishing your app to the App store(s). It is created when you associate the app with one that you have created on the app store portal pages.

    I can't share my file, as it is unique to me and my store account data.

    So if you create your own app on the app store and then right-click on your project (not the solution, the project) and use the menu option:

    Store / Associate App with the Store

    you should be good. If you still get errors, perhaps because you don't have a Store account and can't create (or don't want to create) an app for publishing, try Cleaning the solution and maybe manually creating an empty Package.StoreAssociation.xml file.

    Remember you'll also need to register for Weather Underground and Azure/Bing API keys to use this app as-is, so it's not quite as "press F5 and run!" and a sample could be, sorry! :-)

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.