Click here to Skip to main content
13,146,742 members (79,955 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.2K views
4 bookmarked
Posted 21 Apr 2016

First Windows 10 IoT Core Windows Application

, 21 Apr 2016
Rate this:
Please Sign up or sign in to vote.
So now that I have my device up and running, time to start coding. So I’ll be writing my first application. Objectives I could start coding a complicated app using the GPIO or talking with advanced devices using I2C. But I just wanted to see what was possible on the device first.

Editorial Note

This article is an entry in our Microsoft Azure IoT Contest. Articles in this section are not required to be full articles so care should be taken when voting.

So now that I have my device up and running, time to start coding. So I’ll be writing my first application.

Objectives

I could start coding a complicated app using the GPIO or talking with advanced devices using I2C. But I just wanted to see what was possible on the device first.

The objective of this first application are:

  • Creating a MINIMAL basic UI based application.
  • See if it could be deployed to the device.
  • See my application run on the Raspberry Pi.
  • Start a debugging session, place break points and watch variable values.

Getting Started

Creating a Universal Windows Project

In Visual Studio 2015, I clicked File | New Project….

FirstAppNewProject

Coding

Once the project was loaded, I opened up the main page MainPage.xaml. I created a basic layout, added a TextBlock, a TextBox and a Button. Here is the code:

XAML

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="51"/>
        <RowDefinition Height="51"/>
        <RowDefinition Height="51"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <TextBlock x:Name="textBlock" Grid.Row="1" TextWrapping="Wrap" Text="Hello World!" HorizontalAlignment="Center"/>
    <TextBox x:Name="textBox" Grid.Row="2" TextWrapping="Wrap" Text="" HorizontalAlignment="Center" Margin="5" Width="150"/>
    <Button x:Name="Greet" Content="Button" Grid.Row="3" HorizontalAlignment="Center" Click="Greet_Click"/>
</Grid>

I double clicked on the button to write an event handler. And typed in the following code:

C#

private void Greet_Click(object sender, RoutedEventArgs e)
{
    string greet = "Hello World!";
    if(!string.IsNullOrEmpty(textBox.Text))
    {
        greet = string.Format("Hello {0}!", textBox.Text);
    }
    textBlock.Text = greet;
}

Testing the application

To make sure the application was working as expected I started it from my local machine.

FirstAppStartLocal

As expected, I got a new window with the following in it:

FirstAppStart

I typed in my name, clicked the button and got:

FirstAppWorking

Fantastic! The app works! So I closed the window to stop the debug process before I continue.

Starting on the Raspberry Pi

Now that I have a working app, it’s time to try to run it on the device. To do this:

  1. Change set your debug target to Remote Machine
    FirstAppStartChange
  2. Specify the machine address
    FirstAppStartRemote
  3. Change your build target to ARM
    FirstAppStartRemoteTarget
  4. Click Remote Machine to start the debugging session

Once this is done a number of things will happen:

  1. The application will be built.
  2. If this is the first time, Visual Studio will check some of the requirements on the remote device and install missing packages.
  3. Visual Studio will deploy the application to the remote device
  4. Visual Studio will start the remote debugger for the application on the device
  5. Visual Studio start the application.

This is the build output for this process:
Output Window (Build)

1>------ Build started: Project: HelloWorld, Configuration: Debug ARM ------
1>  HelloWorld -> C:\prog\IoT\HelloWorld\HelloWorld\bin\ARM\Debug\HelloWorld.exe
2>------ Deploy started: Project: HelloWorld, Configuration: Debug ARM ------
2>Creating a new clean layout...
2>Copying files: Total 16 mb to layout...
2>Checking whether required frameworks are installed...
2>Framework: Microsoft.NET.CoreRuntime.1.0/ARM, app package version 1.0.23819.0 is not currently installed.
2>Framework: Microsoft.VCLibs.140.00.Debug/ARM, app package version 14.0.23918.0 is not currently installed.
2>Installing missing frameworks...
2>Registering the application to run from layout...
2>Deployment complete (0:01:52.439). Full package name: "ad63be4b-92ac-472f-8c68-f4537d5b5ce9_1.0.0.0_arm__7j55shkp2zhzg"
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

After that the application will start on the Raspberry Pi.

Debugging

So I first tried the application on the Raspberry Pi. I typed in my name, clicked “Button” and got the expected result.

Now going back to my development machine, I place a break point in the button click event handler.

On the device I type Test in the TextBox and click “Button”.

As expected, on development machine, Visual Studio breaks on the break point. I press F10 to step through and I am debugging.

FirstAppBreakPoint

When I look at the watch I can see all the variables value:

FirstAppWatchWindow

I press F5 to resume and the application continues to run as normal.

To stop the application, you need to stop the debugging session in Visual Studio.

Conclusion

It works! I can create a XML based application and run it on my Raspberry Pi.

One thing I have noticed is that the application on the Raspberry Pi is Modal. You cannot stop the application or get out of it. This will be useful in the future.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ChristianLavigne
Software Developer (Senior)
Canada Canada
I have been programming computers since the mid 1980’s and have been doing so professionally for the past 22 years. I worked on a variety of applications from large consumer oriented commercial applications to enterprise level web applications.

I have been working with the .NET framework since the first version came out around 2000 and got my MCSD (Microsoft Certified Solution Developer) in 2006. Although .NET is my specialty, I do spend time to learn new things and new languages outside of it.

See my blog at: https://christianlavigne.com.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 21 Apr 2016
Article Copyright 2016 by ChristianLavigne
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid