Develop Your First Windows IoT App

Welcome to the exciting world of Windows IoT! This guide will walk you through the essential steps to create and run your very first application on a Windows IoT device.

Prerequisites

Before you begin, ensure you have the following:

Step 1: Set Up Your Development Environment

Install Visual Studio

If you haven't already, download and install Visual Studio 2022. During installation, make sure to select the "Universal Windows Platform development" workload.

Configure Your IoT Device

Ensure your Windows IoT device is properly set up with the latest Windows IoT Core image and connected to your network. You'll need its IP address.

Step 2: Create a New UWP Project

Launch Visual Studio

Open Visual Studio 2022.

Create a New Project

Click on "Create a new project". Search for "Blank App, UWP (C++/WinRT)" or "Blank App, UWP (C#)" and select the appropriate template.

For beginners, we recommend starting with the C# template.

Configure Project Details

Name your project something descriptive, like "MyFirstIoTApp", and choose a location to save it. Click "Create".

Step 3: Write Your First App Code

Let's create a simple app that displays a message. We'll use C# for this example.

Modify MainPage.xaml

Open the MainPage.xaml file in your project. Replace its contents with the following XAML:

<Page
    x:Class="MyFirstIoTApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyFirstIoTApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid Padding="20">
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock Text="Hello, Windows IoT!"
                       FontSize="48"
                       FontWeight="Bold"
                       HorizontalAlignment="Center"
                       Foreground="#0078d4"/>
            <TextBlock Text="Your first app is running!"
                       FontSize="24"
                       HorizontalAlignment="Center"
                       Margin="0,15,0,0"
                       Foreground="#333"/>
        </StackPanel>
    </Grid>
</Page>
Modify MainPage.xaml.cs

Open the MainPage.xaml.cs file. The default code is usually sufficient for a simple app like this, as the UI is defined entirely in XAML.

Step 4: Deploy to Your IoT Device

Configure Deployment Target

In the Visual Studio toolbar, change the debug target from "Local Machine" to "Remote Machine".

Visual Studio debug target

A dialog box will appear. Enter the IP address of your Windows IoT device.

Authentication Mode

Select "Universal (Unencrypted Authentication)" if your device is configured for it, or "Username/Password Authentication" if you've set up credentials. Click "Refresh" if you need to rediscover the device.

Start Debugging

Press the F5 key or click the "Start Debugging" button (the green play icon) in Visual Studio.

Visual Studio will build and deploy your application to the Windows IoT device. After a few moments, you should see your "Hello, Windows IoT!" message appear on the device's display.

Next Steps

Congratulations on running your first Windows IoT app! From here, you can explore: