UWP Development, Markup Extension

Last updated: October 12, 2023

Introduction

Universal Windows Platform (UWP) is a heterogeneous platform developed by Microsoft that provides the tools and APIs necessary for creating applications that run on various Windows 10 devices. UWP applications use a specific UI markup language called XAML (Extensible Application Markup Language) to define their UI. This article presents an in-depth explanation of UWP’s markup extensions along with example code.

Basics of XAML

XAML is used to define all UI components such as UI elements, data binding, and styles. By using XAML, you can declaratively build a UI, and UWP inherently supports various types of UI elements and controls. The syntax of XAML is similar to HTML, but it is designed to operate within the Windows environment.

Example: Basic XAML Structure

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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock Text="Hello, UWP!" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
    </Grid>

</Page>

The Need for Markup Extensions

UWP provides a rich set of UI components by default. However, to meet specific requirements, it may be necessary to extend existing markup languages or create custom controls. Markup extensions can provide ongoing solutions for these needs and enhance UI reusability.

For example, you can create a custom button to implement specific styles or behaviors. This increases code reusability and improves maintainability.

Creating Markup Extensions

Now, let’s look at how to actually create markup extensions. Custom controls can be created by inheriting from UserControl and can be used alongside existing XAML.

Example: Creating a Custom Button

Below is the process for creating a custom button. This button can dynamically set text and background color.

<UserControl
    x:Class="MyApp.CustomButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="customButton">

    <Border Background="{Binding BackgroundColor, ElementName=customButton}" CornerRadius="5" Padding="10">
        <TextBlock Text="{Binding ButtonText, ElementName=customButton}" Foreground="White" FontSize="16"/>
    </Border>

</UserControl>

Code Behind: CustomButton.xaml.cs

using Windows.UI.Xaml.Controls;

namespace MyApp
{
    public sealed partial class CustomButton : UserControl
    {
        public static readonly DependencyProperty ButtonTextProperty =
            DependencyProperty.Register("ButtonText", typeof(string), typeof(CustomButton), null);
        
        public string ButtonText
        {
            get { return (string)GetValue(ButtonTextProperty); }
            set { SetValue(ButtonTextProperty, value); }
        }

        public static readonly DependencyProperty BackgroundColorProperty =
            DependencyProperty.Register("BackgroundColor", typeof(Windows.UI.Color), typeof(CustomButton), null);
        
        public Windows.UI.Color BackgroundColor
        {
            get { return (Windows.UI.Color)GetValue(BackgroundColorProperty); }
            set { SetValue(BackgroundColorProperty, value); }
        }

        public CustomButton()
        {
            this.InitializeComponent();
        }
    }
}

Usage

You can define how to use the custom button as follows.

<local:CustomButton ButtonText="Click Me" BackgroundColor="Blue" />

Considerations When Creating Markup Extensions

When creating markup extensions, there are several important considerations. First, performance. Custom controls can sometimes lead to performance degradation, so it’s advisable to use them only when necessary. Second, accessibility. Custom controls should be developed with accessibility in mind and should be compatible with screen readers.

Lastly, readability. As custom markup becomes more complex, it may become harder to use, so it is beneficial to document it well and provide sufficient examples.

Conclusion

Markup extensions in UWP enhance the flexibility and reusability of UI components, allowing users to meet more specific requirements. By creating custom controls, UWP applications can become more attractive, and these methods can increase efficiency in team collaborations.

The development of UWP will continue to grow, and it is important to enhance understanding and skills in this area. I hope this article helps you in your UWP development journey.

UWP Development, Distributing Without Uploading to Microsoft Store

UWP (Universal Windows Platform) is a powerful platform that allows for the easy development of applications that can run on various Windows 10 devices. While many developers publish their applications to the Microsoft Store for distribution, there are situations where applications need to be distributed through other means. This article will detail how to deploy UWP applications without publishing them to the Microsoft Store.

1. Setting Up the UWP Development Environment

Before starting UWP application development, you need to install Visual Studio and the Windows 10 SDK. The latest version of Visual Studio must be installed, and the UWP development workload should be selected for installation.

1. Download and install Visual Studio.
2. During installation, select "UWP Development" in the "Workloads" section.
3. The Windows 10 SDK will be installed automatically.

2. Application Development

The process of developing a UWP application is as follows.

2.1. Creating a New Project

1. Launch Visual Studio.
2. Click "Create a new project."
3. Search for "UWP" and select "Blank App."
4. Enter the project name and location, then click "Create."

2.2. Configuring the Basic UI

When you create a blank app, the basic App.xaml and MainPage.xaml files are generated. Let’s add the first UI component to the MainPage.xaml file.

<Page
    x:Class="MyApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp">

    <Grid>
        <Button Content="Click Me" Click="Button_Click"/>
    </Grid>
</Page>

In the code above, we add a button and set up an event handler to handle the click event.

2.3. Implementing the Event Handler

private void Button_Click(object sender, RoutedEventArgs e)
{
    var dialog = new MessageDialog("Button was clicked!");
    await dialog.ShowAsync();
}

2.4. Running and Testing the App

Press the F5 key to run the app and check if the dialog appears when the button is clicked.

3. Methods for Deploying UWP Applications

There are various ways to deploy UWP applications without publishing them to the Microsoft Store. The most common methods are to create an App Package for use or to use sideloading.

3.1. Creating an App Package

1. Click the "Build" menu in Visual Studio.
2. Select "Build Solution" to build the application.
3. Choose "File" menu -> "Publish" -> "Create App Package."
4. Follow the package creation wizard to enter the required information, and ultimately create the package.

The generated App Package will be provided in the form of .appx or .msix files. You can use this file to install on other devices.

3.2. Installation via Sideloading

Sideloading is a method of installing UWP apps without going through the Microsoft Store. To do this, developer mode must be enabled.

1. Open Windows Settings.
2. Go to "Update & Security" > "For developers."
3. Enable "Developer mode."

Now the sideloading setup is complete. To install the generated App Package, run the following command using PowerShell.

Add-AppxPackage -Path "C:\path\to\yourpackage.appx"

3.3. Deployment Using PowerShell

You can deploy the UWP app to selected devices using PowerShell. Run PowerShell as an administrator with the appropriate permissions and use the following command.

Invoke-Command -ComputerName "TargetPC" -ScriptBlock {
    Add-AppxPackage -Path "C:\path\to\yourpackage.appx"
}

4. Packaging and Signing

To safely distribute UWP apps, these App Packages require a digital signature. Additional security can be enhanced with signed apps. To sign, you need to create a certificate and use it to sign the package.

1. Use MakeCert.exe to create a certificate.
2. Use SignTool.exe to sign the package.

5. Conclusion

We have explored how to deploy UWP applications without publishing them to the Microsoft Store. You can deploy them by creating App Packages and using sideloading, and can implement it across multiple devices using PowerShell. Choose the appropriate deployment method that fits each business environment and need to utilize UWP applications more effectively.

6. Additional Resources

Such deployment methods can be utilized in various ways depending on the development environment or business needs. As part of an in-depth process of UWP development, we encourage you to apply it effectively to your projects.

UWP Development, Distributing by Uploading to the Microsoft Store

Universal Windows Platform (UWP) development provides a powerful way to create applications within Microsoft’s ecosystem. This article will explain the process of developing UWP apps and distributing them on the Microsoft Store in detail. This process includes the stages of app development, testing, packaging, and final distribution. This will provide a comprehensive understanding of UWP app deployment.

1. What is UWP?

UWP (Universal Windows Platform) is a framework that supports developers in creating applications that can run on various Microsoft devices. UWP-based apps run on Windows 10 and later versions, and can operate on a variety of platforms such as PCs, tablets, smartphones, Xbox, and HoloLens, using the same codebase. One of the biggest advantages of UWP is that it can provide a consistent user experience across multiple devices. Additionally, apps can be distributed on the Microsoft Store to reach users worldwide.

2. Setting Up the UWP Development Environment

To develop UWP apps, you first need to set up the development environment. Here are the basic installation steps.

  1. Install Visual Studio: Visual Studio is required for UWP app development. Download and install Visual Studio 2019 or later.
  2. Select Required Workloads: During the installation of Visual Studio, select the “UWP Development” workload. This will install the tools and packages necessary for developing UWP apps.
  3. Set Up a Testing Device: UWP apps can be tested on actual devices, which must be set to developer mode. While you can also test on a standard PC, it is advisable to test on other platforms for compatibility across different devices.

3. Basic Example of UWP App Development

3.1 Creating a Basic App

Here is how to create a new UWP app project using Visual Studio.

  1. Open Visual Studio and select “Create a New Project”.
  2. Type “Blank App (Universal Windows)” in the search box and select the project.
  3. Set the project name and location, then click the “Create” button.
  4. Set the target version and minimum version, then click “OK”.

Once the project is created, a MainPage.xaml file is generated by default. You can add UI elements here to build the app’s structure.

3.2 Adding UI Elements

Below is how to add basic UI elements like a button and text block.

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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock x:Name="GreetingText" Text="Hello, UWP App!" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,50,0,0"/>
        <Button Content="Click Here" Click="Button_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
</Page>

The code above adds a text block and a button to the page. You will need to add the event handler method for the button click.

3.3 Creating an Event Handler

Add a method to handle the button click event in the MainPage.xaml.cs file.

private void Button_Click(object sender, RoutedEventArgs e)
{
    GreetingText.Text = "The button has been clicked!";
}

Now, when you run the app and click the button, the text block’s content will change. This is a simple example that helps in understanding the basic functionality of a UWP app.

4. Testing UWP Apps

After developing the app, it is essential to perform testing. You can run it in “Debug” mode in Visual Studio to test the app on the basic emulator or connected devices. Here is the testing process.

  1. Run the app. When you run it in debug mode, it will by default execute on the emulator or connected devices.
  2. Review each feature of the app, ensuring that all UI elements are displayed correctly.
  3. Click on the button and other user interaction elements to ensure that they function as expected.

5. Preparing for App Packaging and Distribution

If the app works correctly, you can now prepare for packaging and distribution. Packaging compresses the app into the .appx format for distribution. To do this, follow these steps.

5.1 Creating a Package

  1. From the Visual Studio menu, select “Project” – “Create and Distribute Project”.
  2. Select the packaging options, then click “Next”.
  3. Enter information such as app name, version, architecture, etc.
  4. Click “Package” to generate the .appx file.

5.2 Signing the Package

To distribute through the Microsoft Store, the package must be signed. This ensures the app’s reliability. To sign the package, you need to create a developer certificate and use it.

dotnet publish -f win10 -c Release --self-contained

6. Distributing to the Microsoft Store

Once packaging and signing are complete, you are ready to distribute the app to the Microsoft Store. The distribution process is as follows.

6.1 Registering a Developer Account

You need to register a developer account to distribute the app to the Microsoft Store. Create an account and log in, then navigate to the developer dashboard.

6.2 Submitting the App

  1. Select “New App” in the dashboard, then enter the app information.
  2. Upload the package and add marketing materials such as app description, screenshots, and icons.
  3. Set the app’s price, country, and system requirements, then click the “Submit” button.

6.3 Review and Approval

The submitted app undergoes Microsoft’s review process, during which the app’s functionality and user experience are evaluated. After the review is completed, you will be notified of the approval or rejection. The approved app will be distributed on the store.

7. Conclusion and Additional Resources

Developing and distributing an app using UWP may seem complex at first, but by systematically following each step, it can be successfully accomplished. UWP is a powerful platform that can provide a consistent user experience across multiple devices, which offers opportunities to connect with users worldwide.

If you wish to gain a deeper understanding of UWP development, please refer to the following resources:

I hope this article has been helpful in UWP development and distributing apps to the Microsoft Store. Wishing you success in your app development!

UWP Development, Creating a New App for the Microsoft Store

UWP (Universal Windows Platform) is an application framework developed by Microsoft that allows you to create apps using the same code across various Windows devices. UWP supports a wide range of platforms such as desktop, tablet, mobile, and Xbox, enabling developers to easily deploy apps that work in all environments. In this article, we will look at the basic concepts of UWP app development and detail the process of distributing apps through the Microsoft Store.

1. Overview of UWP

UWP applications run on Windows 10 and later versions and are distributed through the Windows Store. The main features of UWP include:

  • Execution on various devices: UWP runs on a wide range of Windows devices, including PCs, tablets, Xbox, and IoT devices.
  • Modern UI: It offers a sleek user interface (UI) based on the Fluent Design system.
  • Integration with smartphone apps: UWP is compatible with Windows 10 Mobile, allowing the expansion of smartphone apps.

2. Setting Up a UWP Development Environment

To begin UWP development, you need a Visual Studio environment. Below is how to install Visual Studio and set up a UWP development environment:

2.1 Installing Visual Studio

  1. Visit the Visual Studio download page.
    Visual Studio Download
  2. Run the Visual Studio installer, and in the Workload Selection step, check the Desktop development with C# checkbox.
  3. In the Developer Tools section, select Universal Windows Platform Development.
  4. After completing the installation, launch Visual Studio.

2.2 Creating a New UWP Project

  1. After running Visual Studio, select File > New > Project.
  2. In the search box, type Blank App (Universal Windows), select it, and click Next.
  3. Set the project name and location, then click the Create button.
  4. Select the target version and minimum version, then click OK.

3. Designing and Developing UWP Apps

Let’s look at the basic structure of a UWP app. UWP apps primarily use XAML (Extensible Application Markup Language) to design the UI and C# or C++ to implement app logic.

3.1 Designing UI with XAML

You can create the user interface of a UWP app using XAML. Below is an example of XAML code that includes a basic UI:

        
        <Page
            x:Class="MyApp.MainPage"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

            <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
                <TextBlock Text="Hello, UWP!" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Button Content="Click Me" Click="Button_Click" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,20"/>
            </Grid>
        </Page>
        
        

3.2 Implementing App Logic with C#

Use C# code-behind to configure the logic for interacting with UI elements. Below is code that handles the button click event:

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

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

                private void Button_Click(object sender, RoutedEventArgs e)
                {
                    TextBlock textBlock = (TextBlock)FindName("MyTextBlock");
                    textBlock.Text = "Button Clicked!";
                }
            }
        }
        
        

4. Testing and Debugging the App

Testing and debugging are crucial processes during UWP app development. You can easily test it through Visual Studio.

4.1 Local Testing

  1. Click the Debug button in the upper menu to run the app.
  2. Alternatively, you can press the F5 key to run in debug mode.

4.2 Using the Emulator

You can test the operation on various devices using the Windows Holographic or Mobile emulator. To set up the emulator, you can add it through Visual Studio by going to Tools > Android Emulator Manager.

5. Distributing the App to the Microsoft Store

Once app development and testing are complete, the last step is to distribute the app to the Microsoft Store. Below are the steps in the distribution process:

5.1 App Packaging

  1. Configure a Release Build in Visual Studio.
  2. Select Build > [Project Name] > Create Package > Create App Package from the menu.
  3. In the App Package creation wizard, select the location to save and various options for generating the package.

5.2 Registering with Dev Center and Submitting the App

To submit your app to the Microsoft Store, you need to register for a developer account in the Azure Dev Center. After registration, you can submit the app through the following procedure:

  1. Log in to the Dev Center and go to My Apps.
  2. Click Create New App and enter the app name and information.
  3. Upload the app package and configure the business model and pricing.
  4. Click the Submit button to request a review from Microsoft.

6. Conclusion

With the UWP platform, you can easily develop apps that can be used across various Windows devices and distribute them to users worldwide through the Microsoft Store. I hope the content covered in this article has helped you understand the basic flow of UWP app development. The next steps could be to improve UI/UX, or explore how to expand app functionality by connecting to a database or API.

UWP Development, Registering a Microsoft Developer Account

Today, app development has become one of the most important technologies. Among them, UWP (Universal Windows Platform) is a powerful platform for creating applications that can run on a variety of devices. In this article, we will detail the process of registering a Microsoft developer account, which is the first step needed to develop UWP apps.

1. What is UWP?

UWP is a platform for creating apps that can run on Windows 10 and later platforms, operating on various devices like PCs, tablets, Xbox, and HoloLens. UWP supports various languages and frameworks such as .NET, C#, C++, HTML, CSS, and JavaScript, providing developers with flexibility.

2. Importance of a Developer Account

A Microsoft developer account is an essential element for developing and distributing UWP apps. Without a developer account, you cannot publish apps to the Microsoft Store, and you may lose access to certain APIs and services. Thus, it is a necessary process for successful UWP development.

3. Procedure for Registering a Developer Account

The process of registering a Microsoft developer account includes the following steps.

Step 1: Create a Microsoft Account

The first step is to create a Microsoft account. If you already have an account, you can skip this step. Please follow the steps below:

  1. Open your web browser and go to the Microsoft account creation page.
  2. Enter your basic information such as email address, password, gender, and date of birth.
  3. Verify that you are not a robot by completing the captcha, and click the ‘Next’ button.

Step 2: Register for a Developer Account

After creating a Microsoft account, you need to upgrade it to a developer account. Please proceed with the following steps:

  1. Visit the Microsoft Developer Center.
  2. Click on the ‘Join’ or ‘Sign In’ button at the top right and log in with the Microsoft account you just created.
  3. After logging in, find the ‘Register for Developer Program’ section. Here, you will need to enter the necessary information to register for a developer account.

Step 3: Understand and Agree to the Developer Program Terms

Before registering for a developer account, you must read and agree to Microsoft’s Developer Program Terms. Carefully read the terms and click the ‘Agree’ button.

Step 4: Pay the Fee

Registering for a Microsoft developer account requires an annual fee. The fee varies depending on the type of account, typically $19 or $99. Pay the fee using a credit card to complete your order. Both prepaid and postpaid options are available, so choose what suits your situation.

Step 5: Confirm Account Activation

After registering your developer account, check your email for a confirmation message that your registration has been completed. Click the link in the email to activate your developer account properly.

4. Setting Up the Basic Environment for UWP App Development

Once your developer account is activated, you are now ready to develop UWP apps. The next step is to set up your development environment. You will need to install and use Visual Studio.

Installing Visual Studio

  1. Go to the Visual Studio download page and select the version of Visual Studio you want. The Community version is usually available for free and includes the tools needed for UWP development.
  2. Run the downloaded installation file and select the ‘UWP development’ workload to install it.

5. Conclusion

Now you have completed all the preparations necessary to develop UWP apps. Although registering a Microsoft developer account may seem complex at first, it is an important first step into the developer ecosystem. Based on what you have learned in this process, try creating your own UWP app. The UWP platform offers excellent opportunities to create applications that work across various devices.

In the next post, we will cover the basics of UWP app development. If you have any questions or feedback, please leave a comment below!