Welcome to the exciting world of Windows IoT! This guide will walk you through the essential steps to create and deploy your very first application on a Windows IoT device.
Before you begin, ensure you have the following:
For detailed setup instructions, refer to the official Windows IoT documentation.
Let's create a simple "Hello, World!" Universal Windows Platform (UWP) app.
Visual Studio will generate a basic UWP project structure.
We'll modify the main page to display a message.
Open MainPage.xaml and replace its content with the following:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyFirstIoTApp.MainPage"
BackgroundColor="{DynamicResource PageBackgroundColor}">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, Windows IoT!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Your first app is running!"
SemanticProperties.HeadingLevel="Level1"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Now, open MainPage.xaml.cs and replace its content with the following:
using Microsoft.Maui.Controls;
using System;
namespace MyFirstIoTApp
{
public partial class MainPage : ContentPage
{
int count = 0;
public MainPage()
{
InitializeComponent();
}
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
}
}
}
This is where you connect your development PC to your IoT device.
If the deployment is successful, your "Hello, Windows IoT!" app should launch on your IoT device!
Congratulations! You've built and deployed your first Windows IoT app. From here, you can: