UWP Development, What is UWP

UWP (Universal Windows Platform) is a platform introduced by Microsoft for application development based on the Windows 10 operating system. With UWP, developers can write applications that can run on various devices, and these applications will work on desktops, tablets, Xbox, HoloLens, and many other devices that use Windows 10.

Main Features of UWP

  • Broad device support: UWP can run on all Windows 10 devices. This means that developers can create applications that can be used across all devices with a single development effort.
  • Modern UI framework: UWP uses XAML (Extensible Application Markup Language) to allow designers to create user interfaces, making it easy to implement vibrant and responsive UIs.
  • Store distribution: UWP apps can be distributed through the Microsoft Store, making them easily accessible to users. Developers can also distribute their apps outside of the store if necessary.
  • Consistency of APIs: UWP provides the same set of APIs across various Windows 10 devices, allowing developers to write code in a consistent manner for diverse hardware.
  • Support for advanced features: UWP supports application development leveraging advanced technologies such as artificial intelligence, machine learning, and AR/VR (augmented reality/virtual reality).

Structure of UWP Apps

UWP applications typically have the following structure:

  • App.xaml: Contains the overall settings of the application. It defines resource dictionaries, start pages, etc.
  • MainPage.xaml: The page that defines the main user interface of the application.
  • Views and ViewModels: Maintains the structure of the application using the MVVM (Model-View-ViewModel) pattern.
  • Assets: A folder that contains images, styles, and other resources.

Setting up the UWP Development Environment

The environment required for developing UWP apps includes:

  • Windows 10: The Windows 10 operating system is required for UWP development.
  • Visual Studio: Microsoft’s integrated development environment, which includes all the tools needed for UWP app development.
  • Windows 10 SDK: You must install the software development kit (SDK) for UWP app development.

Example of UWP App Development

Now, let’s create a simple UWP app. This application is a straightforward app that displays a greeting when the user enters their name and clicks a button.

1. Create a new UWP project

  1. Open Visual Studio, and select “File” menu then “New” -> “Project”.
  2. Select C# as the language and choose the “Blank App (Universal Windows)” template, then name the project and click “Create”.
  3. You can set the target and minimum versions at this time; using the defaults is fine.

2. Design the user interface with XAML

Open MainPage.xaml in Visual Studio and modify it as follows:


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

    <Grid>
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBox x:Name="NameInput" PlaceholderText="Enter your name" />
            <Button Content="Greet" Click="GreetButton_Click" />
            <TextBlock x:Name="GreetingText" FontSize="20" Margin="10" />
        </StackPanel>
    </Grid>
</Page>

3. Implement logic with C#

Open the MainPage.xaml.cs file and add the following code:


using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace HelloWorld
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void GreetButton_Click(object sender, RoutedEventArgs e)
        {
            var name = NameInput.Text;
            GreetingText.Text = $"Hello, {name}!";
        }
    }
}

4. Run the app

After writing the code, you can run the app (Debug → Start or F5 key) to test it on the emulator or an actual device.

Conclusion

UWP is a platform that allows you to develop powerful applications that can run on various Windows 10 devices. Thanks to modern UI design tools and robust API support, developers can create apps that provide rich experiences tailored to user needs. The advantages of UWP development are numerous, equipping you with all the tools needed to deliver better user experiences. Leverage these features to develop your own UWP applications.