Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

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.

image

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 (https://weatherview.codeplex.com/)

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;

image

image

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



Tags:

Follow the Discussion

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

    Error Images.

    1. http://jmp.sh/TegJ8oc

    2. http://jmp.sh/Q2v1H7Z

  • Greg Duncangduncan411 It's amazing what a professional photographer can do...

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

  • John KennedyJohn 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.

  • Greg Duncangduncan411 It's amazing what a professional photographer can do...

    @John Kennedy:Thanks John!

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

  • JohnJohn

    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! :-)

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.