Getting Started with Windows UWP

Welcome to the Universal Windows Platform (UWP) development guide! This section will walk you through the essential steps to begin building modern applications that run across the Windows ecosystem.

What is UWP?

The Universal Windows Platform (UWP) is a software platform created by Microsoft and first introduced with Windows 10. It allows developers to create applications that can run on all Windows 10 devices, including PCs, Xbox, HoloLens, and more, with a single codebase. UWP apps are distributed through the Microsoft Store.

Prerequisites

Before you start, ensure you have the following:

  • A PC running Windows 10 or later.
  • An internet connection.
  • Visual Studio: The recommended IDE for UWP development. You can download the Community Edition for free from the Visual Studio website. Ensure you select the "Universal Windows Platform development" workload during installation.

Your First UWP App: A Step-by-Step Guide

  1. Create a New Project:

    Open Visual Studio. Select "Create a new project". Search for "Blank App (Universal Windows)" and choose the C# or C++ template.

  2. Configure Your Project:

    Give your project a name and choose a location. Click "Create". Visual Studio will prompt you to select the target version and minimum version of Windows 10. For beginners, it's often best to choose reasonably recent versions.

  3. Understand the Project Structure:

    You'll see several files. Key ones include:

    • App.xaml and App.xaml.cs: The application entry point and core logic.
    • MainWindow.xaml (or similar): Defines the main window's UI.
    • MainWindow.xaml.cs (or similar): Contains the code-behind for the main window.
  4. Design Your UI:

    Open the .xaml file for your main window. Visual Studio provides a design view and a XAML editor. You can drag and drop controls from the Toolbox onto the design surface or write XAML directly.

    Here's a simple example of adding a TextBlock:

    <StackPanel>
      <TextBlock Text="Hello, UWP World!" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </StackPanel>
  5. Add Interaction Logic:

    Let's add a button to change the text. First, modify your XAML:

    <StackPanel Margin="20">
      <TextBlock x:Name="GreetingTextBlock" Text="Hello, UWP World!" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,20"/>
      <Button Content="Change Text" HorizontalAlignment="Center" Click="ChangeTextButton_Click"/>
    </StackPanel>

    Now, in your .xaml.cs file, add the event handler for the button click:

    // In your MainWindow.xaml.cs file

    private void ChangeTextButton_Click(object sender, RoutedEventArgs e)
    {
      GreetingTextBlock.Text = "UWP Development is Fun!";
    }
  6. Run Your Application:

    Press the "Start" button (or F5) in Visual Studio. Your app will build and launch. Click the "Change Text" button to see your interaction in action!

Next Steps

Congratulations on building your first UWP app! Here are some resources to continue your journey: