"Hello World" is a programming sample used to introduce the fundamentals. If you're new to programming, or to WinRT development, follow this tutorial to create a basic app that displays a "Hello World" message, and works on both Windows Phone 8.1 and Windows 8.1.
Some menu options are in slightly different places in Visual Studio Express.
FILE > New > Project:
The New Project window will open.
2. Navigate the menu tree on the left to find the Universal Apps templates (Installed > Templates > Visual C# > Store Apps > Universal Apps).
If you don't see the universal templates your Visual Studio might need an update. Check for updates via TOOLS > Extensions and Updates on the main menu.
3. From the templates listed in the middle area, select Blank App (Universal Apps).
4. Type HelloWorld in the Name: field.
5. Click OK.
A universal app solution consists of three projects (A, B, and C), each with its own code (and other files). The projects in a universal Windows app are:
a. Windows 8.1 (Store) project
b. Windows Phone 8.1 project
c. The shared project.
You're probably wondering why there are separate projects when the app is supposed to be universal...
What does Universal Mean?
Phone app = shared project + phone project
Windows app = shared project + Windows Store project
We're going to add a few lines of code to display a popup with the traditional "Hello World" message. In the Solution Explorer, find and double-click the App.xaml.cs
file:
The triangles expand file groups. Some items have linked files (a .xaml file is for XAML code – eXtensible Markup Language, and a .cs file is for C# code). Usually the XAML defines the user interface (it's similar to HTML), and C# is the program that runs 'behind the scenes' (called 'code behind'). Expand App.xaml within the HelloWorld.Shared project to find App.xaml.cs.
using
System;
Windows.UI.Xaml;
using Windows.UI.Popups;
Windows.UI.Popups;
protected override void OnLaunched(LaunchActivatedEventArgs e)
protected
override
void
OnLaunched(LaunchActivatedEventArgs e)
Window.Current.Activate();
MessageDialog msg = new MessageDialog("Hello World");msg.ShowAsync();
MessageDialog msg =
new
MessageDialog(
"Hello World"
);
msg.ShowAsync();
These lines create a message dialog box called msg containing the words "Hello World", and then displays it. And we're done with the coding. This is just "Hello World" after all!
You should see this: Click the stop button on the Visual Studio menu bar to stop the app:
*The phone must be developer unlocked. If you have a developer account you can unlock your phone from the TOOLS > Windows Phone 8.1 menu. The phone needs to be plugged into the computer (and recognised, and the screen must be unlocked) to deploy the app.
You should see this:
We created a new universal app, with three projects (one each for Windows Phone and Windows Store, and a unifying shared project). Because Windows Phone and Windows Store apps both run on the WinRT framework we were able to add code to the shared project that was automatically included in both versions of the app. We then ran and tested the app on both PC and phone.
When it comes time to publish a universal app for uploading to the stores, you would actually build your app twice and upload separate packages to the two stores (Windows Phone Store and Windows Store). You should now have a fair idea of how to create a project, and know the basics of how Visual Studio organises a solution. You're well on your way to building great universal Windows apps.