Modernizing Your Windows Applications with the Windows App SDK and WinUI - Matteo Pagani - E-Book

Modernizing Your Windows Applications with the Windows App SDK and WinUI E-Book

Matteo Pagani

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

If you're a developer looking to improve and modernize your existing LOB applications to leverage modern Windows features without having to rewrite the entire application from scratch, this book is for you. You’ll learn how to modernize your existing Windows Forms, WPF, and UWP applications and enrich them with the latest Windows features.
Starting with sample LOB applications that cover common scenarios, you'll learn the differences between various components and then focus on design features for improved visual aspects like accessibility and responsive layouts.
The book shows you how to enhance your existing applications using Windows App SDK components and various Windows APIs, resulting in deeper integration with the operating system. You’ll be taking a closer look at WinML, which enables Windows applications to evaluate machine learning models offline and leverage the power of your machine, or notifications, to engage with your users in a more effective way. You’ll also learn how to make your application deployment-ready by distributing it using various platforms like the Microsoft Store or websites.
By the end of this Windows book, you'll be able to create a migration plan for your existing Windows applications and put your knowledge to work by enhancing your application with new features and integrating them with the Windows ecosystem.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 588

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Modernizing Your Windows Applications with the Windows App SDK and WinUI

Expand your desktop apps to support new features and deliver an integrated Windows 11 experience

Matteo Pagani

Marc Plogas

BIRMINGHAM—MUMBAI

Modernizing Your Windows Applications with the Windows App SDK and WinUI

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Associate Publishing Product Manager: Sathyanarayanan Ellapulli

Senior Editor: Rohit Singh

Content Development Editor: Tiksha Lad

Technical Editor: Maran Fernandes

Copy Editor: Safis Editing

Project Coordinator: Manisha Singh

Proofreader: Safis Editing

Indexer: Subalakshmi Govindhan

Production Designer: Shyam Sundar Korumilli

Marketing Coordinator: Sonakshi Bubbar

First published: March 2022

Production reference: 1280322

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80323-566-0

www.packt.com

To my wife, Angela, for being a constant source of love, inspiration, and support. And to my daughter, Giulia, for teaching me to see the world from a different perspective.

– Matteo Pagani

Dedicated to anyone who still holds on to reason and scientific knowledge in today's turbulent times.

– Marc Plogas

Contributors

About the authors

Matteo Pagani is the lead of the Windows App Consult team in Microsoft. In his role, he supports developers and companies all around the world, enabling them to learn and adopt the latest development tools and technologies in the Microsoft 365 and .NET ecosystem. He has a strong passion for client development, which he loves to share with other developers by writing articles, blog posts, and books, and by speaking at conferences all around the world. Before joining Microsoft, he was a Microsoft MVP in the Windows Development category and a Nokia Developer Champion for almost 5 years.

I would like to thank my wife, Angela, and my daughter, Giulia, for their ongoing support and patience during the writing process. Next, I wish to thank my friend Marc for being a partner in crime. Then I would like to thank Sebastien Bovo and Xianghui Li for the excellent feedback they provided during the review process. Lastly, I would like to thank Microsoft and the App Consult team for supporting me on this journey.

Marc Plogas is an Azure AppConsult engineer at Microsoft and was on the Windows AppConsult team in his previous role. He works with start-ups and large companies on IoT, mixed reality, and software architecture. Tinkering with computers has always been his passion – since the tender age of 6. Therefore, he is interested in many development topics, including client development and machine learning, and enjoys all the challenges that can be solved with software engineering. Before joining Microsoft, Marc was a freelance software developer for many years, creating mobile and LoB applications.

First, I would like to thank my wife and daughter for their support, encouragement, and patience. I would also like to thank my friend Matteo, who covered my back more than once and encouraged me with memes and GIFs. I would also like to thank my team lead, David, who helped me free up time to work on the book. I would also like to thank my work-family at Microsoft, namely, both AppConsult teams, for the opportunity they have given me, especially my colleagues, Sebastien Bovo and Xianghui Li, for their feedback.

About the reviewers

Sebastien Bovo has been a member of the worldwide Windows AppConsult team dedicated to the Windows Enterprise Developer product group at Microsoft. His everyday life involves helping customers, partners, and developers in creating Windows and holographic applications. He has worked on Proof of Concept, debugged code, and provided knowledge transfers and workshops for developers.

He loves sharing his experience and knowledge with others to make them better! In particular, he has been a speaker at technical conferences, including BUILD in Seattle, IGNITE in Orlando, and around Europe for the Windows Insider Dev Tour!

Sebastien has just assumed the role of cloud solution architect to help customers modernize and innovate with Microsoft Cloud.

Xianghui Li has solid solution analysis skills and extensive development experience in .NET, web solutions, and distributed systems. He has mastered Azure IaaS and PaaS, as well as IoT deployment, development, and troubleshooting. He is good at unmanaged/managed debugging and has successfully designed, developed, and released several debugging diagnostic tools in Global Azure and Microsoft Internal.

He now works as a Windows Application Consult in Microsoft, focusing on Microsoft 365, Windows development, and cutting-edge software techniques.

Table of Contents

Preface

Section 1: Basic Concepts

Chapter 1: Getting Started with the Windows App SDK and WinUI

Technical requirements

A brief history of Windows UI platforms

Introducing the Windows App SDK and WinUI 3.0

The role of the new .NET runtime

Exploring the Windows App SDK

Choosing the right deployment model

Managing the dependency with the Windows App SDK

Packaged apps

Unpackaged apps

Upgrading the Windows App SDK runtime

Creating the first Windows App SDK project

A new packaged WinUI C# application

Using a separate packaging project

A new unpackaged WinUI application

Adding support to an existing application

Building libraries and components

Using a WinUI class library

Using a .NET class library

Summary

Questions

Further reading

Section 2: Modernization Journey

Chapter 2: The Windows App SDK for a Windows Forms Developer

Technical requirements

Introducing XAML

Using namespaces

Customizing controls with properties

Reacting to changes with event handlers

Styling your applications with resources

Sharing a resource with a whole application

Using dictionaries to organize resources

Reusing multiple resources with styles

Understanding animations

Playing an animation

Customizing the template of a control

Using a Universal Windows Platform project

Using the XAML source code

Managing the states of a control

Data binding

Binding with C# objects

Implementing the INotifyPropertyChanged interface

Displaying collections of data with DataTemplates

Creating user controls

Summary

Questions

Chapter 3: The Windows App SDK for a WPF Developer

Technical requirements

Importing XAML namespaces

Binding with x:Bind

Different context

Default binding mode

Using x:Bind to define a DataTemplate

Event binding

Functions

Using the dispatcher

Improving dispatcher usage in asynchronous scenarios

Localizing your applications

Translating the user interface

Handling translation in code

A better way to manage localization

Support localization in a packaged app

Summary

Questions

Chapter 4: The Windows App SDK for a UWP Developer

Technical requirements

Moving to a new namespace

Working with the UI thread

Controlling the application's life cycle

Supporting the application's activation

Supporting multiple activation paths

Application instancing

Supporting advanced redirection scenarios

Managing the application's window

Using the AppWindow class

Performing operations in the background

Summary

Questions

Chapter 5: Designing Your Application

Technical requirements

Creating a responsive layout

Using effective pixels

Adapting the UI

Using the right controls to build a responsive layout

Supporting navigation

Implementing the NavigationMenu control

Handling the navigation

Supporting the page's life cycle

Supporting page transitions

Managing backward navigation

Adding sections to the footer

Displaying a menu at the top

Supporting Windows themes

Forcing a specific theme

Creating animations

Creating animations in C#

Creating animations in XAML

Applying effects and animating them

Connected animations

Using a connected animation in a master-detail scenario

Using animated icons

Exploring the WinUI controls

Summary

Questions

Chapter 6: Building a Future-Proof Architecture

Technical requirements

Learning the basic concepts of the MVVM pattern

Moving a bit deeper into the MVVM pattern

Exploring frameworks and libraries

Supporting actions with commands

Enabling or disabling a command

Making your application easier to evolve

Exchanging messages between different classes

Managing navigation with the MVVM pattern

Navigating to another page

Passing parameters from a ViewModel to another

Summary

Questions

Section 3: Integrating Your App with the Windows Ecosystem

Chapter 7: Migrating Your Windows Applications to the Windows App SDK and WinUI

Technical requirements

Getting an understanding of general migration guidance

Exploring the sample application

Updating your applications to .NET 6

The .NET Portability Analyzer

Upgrading your solution

Migrating a Windows Forms application

Supporting navigation

Migrating from the code-behind approach to the MVVM pattern

Migrating the DataGrid control

Migrating the Details page

Migrating a WPF application

Themes

Migrating a UWP app

Migrating the dispatcher

Activation

Managing the life cycle

Summary

Questions

Chapter 8: Integrating Your Application with the Windows Ecosystem

Technical requirements

Integrating APIs from the Universal Windows Platform

Taking advantage of the Bing Maps service

Introducing biometric authentication

Working with files and folders

Working with folders

Working with files

Using the local storage in packaged apps

Using local storage to store settings

Working with file pickers

Supporting the sharing contract

Building the source app

Building the target app

Integrating web experiences in your desktop application

Adding the WebView2 control to your page

Enabling interactions between the native and web layers

Distributing the WebView2 runtime with your applications

Summary

Questions

Chapter 9: Implementing Notifications

Technical requirements

Sending a notification from a Windows application

Working with toast notifications

Supporting toast notifications in packaged apps

Adding images

Customizing the application's name and the timestamp

Tagging a toast notification

Scheduling a notification

Adding interaction to a notification

Handling activation from a notification

Supporting user input

Displaying a progress bar

Displaying a badge in the taskbar

Implementing push notifications

Implementing the backend

Limitations of the current implementation

Summary

Questions

Chapter 10: Infusing Your Apps with Machine Learning Using WinML

Technical requirements

A brief introduction to ONNX and WinML

Evaluating an ONNX model with WinML

Loading the ONNX model

Loading the labels

Preparing the model input

Performing the evaluation

Sorting the results

Putting everything together

Training and using your own machine learning model

Training the model

Testing the model

Exporting the model

Summary

Questions

Section 4: Distributing Your Application

Chapter 11: Publishing Your Application

Understanding the MSIX packaging technology

Built-in optimizations around network bandwidth and disk space

Deployment flexibility

Tamper protection and signature enforcement

Registry virtualization

Local application data virtualization

The Virtual File System (VFS)

MSIX limitations

The anatomy of an MSIX package

Creating and signing an MSIX package

Choosing a distribution method

Choosing a signing method

Selecting and configuring packages

Signing an MSIX package

Publishing your application to Microsoft Store

Submitting an MSIX packaged application

Submitting an unpackaged application

The certification process

Submitting updates

Deploying your applications from a website using AppInstaller

Generating an AppInstaller file with Visual Studio

Generating an AppInstaller file with AppInstaller File Builder

Deploying an AppInstaller file

Updating an application automatically

Updating an application from code

Supporting updates and repairs

Publishing your application to the Windows Package Manager repository

Creating a manifest for Windows Package Manager

Summary

Questions

Chapter 12: Enabling CI/CD for Your Windows Applications

Technical requirements

Introducing CI/CD pipelines

Building a Windows application in a CI/CD pipeline

Pulling the source code

Adding MSBuild to the system's path

Building the Windows application

Publishing the artifact

Testing the workflow

Supporting versioning

Installing the tool and generating the version number

Setting the version number

Handling signing

Storing the certificate on GitHub

Automating the deployment

Generating the App Installer file

Deploying our Windows application

Improving the deployment story

Summary

Questions

Further reading

Assessments

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Why subscribe?

Other Books You May Enjoy

Preface

Windows desktop applications continue to play a critical role in many scenarios among consumers and enterprises. Many of them have been the outcome of very long development processes that involved technologies that are now outdated, hard to maintain, and hard to integrate with the latest Windows innovations.

In this book, we'll show how you can modernize the UI and the features of your application using the Windows App SDK and WinUI, the latest iteration of the Windows developer platform.

Who this book is for

This book is for developers who are building Windows applications with Windows Forms, WPF, and UWP with a special focus on Line-of-Business (LoB) apps for enterprises. Basic knowledge of Windows app development, .NET/C#, and Visual Studio will assist with understanding the concepts covered in this book.

What this book covers

Chapter 1, Getting Started with the Windows App SDK and WinUI, covers the current status of the developer platform ecosystem and explains how you can start a new Windows App SDK project and how you can integrate its features into an existing Windows application.

Chapter 2, The Windows App SDK for a Windows Forms Developer, covers Windows Forms, which is one of the most popular development platforms for Windows. In this chapter, you'll learn how many concepts from Windows Forms are translated to the Windows App SDK and WinUI.

Chapter 3, The Windows App SDK for a WPF Developer, covers WPF, which has many similarities with the Windows App SDK and WinUI, starting from the shared UI layer based on XAML. In this chapter, you'll learn the key differences between WPF and WinUI.

Chapter 4, The Windows App SDK for a UWP Developer, explains that the Windows App SDK and WinUI are the direct successors to the UWP ecosystem. However, they are based on a different development model. In this chapter, we'll learn the differences we have to take into account.

Chapter 5, Designing Your Application, explains that building the UX of your application in the right way is critical to achieving success. This chapter will focus on important design elements, such as navigation, animations, and responsive layouts.

Chapter 6, Building a Future-Proof Architecture, explains that Windows desktop applications are often built to support critical tasks for many years to come. As such, building a future-proof architecture is critical to ensure you don't have to rebuild your application from scratch every time there's a requirement change. In this chapter, we'll learn how the MVVM pattern can help you build applications that are easy to maintain, test, and evolve over time.

Chapter 7, Migrating Your Windows Applications to the Windows App SDK and WinUI, puts into practice all the knowledge we acquired in the previous chapters to migrate existing Windows applications built with Windows Forms, WPF, and UWP to the Windows App SDK and WinUI.

Chapter 8, Integrating Your Application with the Windows Ecosystem, explains that Windows includes many innovative features that can be integrated into your application, such as Windows Hello and Geolocation. In this chapter, we'll learn how to use them in your Windows applications.

Chapter 9, Implementing Notifications, covers notifications, which play a key role in modern applications, delivering critical information to users. As such, Windows includes a powerful notification ecosystem, which you can integrate into your applications.

Chapter 10, Infusing Your Apps with Machine Learning Using WinML, explains that machine learning and artificial intelligence are two of the most important topics in the technology ecosystem. Windows enables developers to turn their machines into part of the edge ecosystem by supporting the evaluation of machine learning models without an internet connection and using the full power of the device. In this chapter, we'll learn how to integrate this platform, called WinML, into your Windows applications.

Chapter 11, Publishing Your Application, explains that developing a great application isn't enough to be successful. You have also to make it available to your users so that they can acquire it in the easiest possible way. In this chapter, we're going to explore the deployment opportunities offered by MSIX and platforms such as the Microsoft Store and App Installer.

Chapter 12, Enabling CI/CD for Your Windows Applications, covers DevOps, which is one of the key approaches nowadays to be successful in software development. In this chapter, we'll learn how you can use two of the key DevOps pillars, continuous integration and continuous deployment, to deliver your Windows applications in a more reliable, fast, and effective way.

To get the most out of this book

To build Windows desktop applications with the Windows App SDK and WinUI, you will need the following:

To follow the last chapter of the book, you will need also a GitHub account.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Modernizing-Your-Windows-Applications-with-the-Windows-Apps-SDK-and-WinUI. If there's an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781803235660_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "You must use this initialization code before setting the Source property in XAML or calling the EnsureCoreWebView2Async() method."

A block of code is set as follows:

<VariableSizedWrapGrid Orientation="Horizontal"

MaximumRowsOrColumns="3" ItemHeight="200" ItemWidth="200">

    <Rectangle Fill="Red" />

    <Rectangle Fill="Blue" />

    <Rectangle Fill="Green" />

    <Rectangle Fill="Yellow" />

</VariableSizedWrapGrid>

Any command-line input or output is written as follows:

winget install Microsoft.Edge

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: "Click on Upload files and wait for the process to finish."

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you've read Modernizing Your Windows Applications with the Windows App SDK and WinUI 3, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.

Section 1: Basic Concepts

Section 1 will set the stage for working with the Windows App SDK and WinUI. The chapters will guide developers in understanding the current state of Windows app development, how to start a new project, and the key concepts to know, regardless of the starting technology.

This section contains the following chapter:

Chapter 1, Getting Started with the Windows App SDK and WinUI