Learn WinUI 3.0

Book description

A beginner's guide to building Windows applications with WinUI for UWP and desktop applications

Key Features

  • Create modern Windows 10 applications and gain access to UI controls that were previously limited to UWP applications
  • Discover how to modernize your existing Win32 apps with a modern Windows 10 UI
  • Learn to embed a single page application (SPA) in a WinUI application with a web framework like Blazor

Book Description

WinUI 3.0 takes a whole new approach to delivering Windows UI components and controls, and is able to deliver the same features on more than one version of Windows 10. Learn WinUI 3.0 is a comprehensive introduction to WinUI and Windows apps for anyone who is new to WinUI, Universal Windows Platform (UWP), and XAML applications.

The book begins by helping you get to grips with the latest features in WinUI and shows you how XAML is used in UI development. You'll then set up a new Visual Studio environment and learn how to create a new UWP project. Next, you'll find out how to incorporate the Model-View-ViewModel (MVVM) pattern in a WinUI project and develop unit tests for ViewModel commands. Moving on, you'll cover the Windows Template Studio (WTS) new project wizard and WinUI libraries in a step-by-step way. As you advance, you'll discover how to leverage the Fluent Design system to create beautiful WinUI applications. You'll also explore the contents and capabilities of the Windows Community Toolkit and learn to create a new UWP user control. Toward the end, the book will teach you how to build, debug, unit test, deploy, and monitor apps in production.

By the end of this book, you'll have learned how to build WinUI applications from scratch and modernize existing WPF and WinForms applications using WinUI controls.

What you will learn

  • Get up and running with WinUI and discover how it fits into the landscape of Project Reunion and Windows UI development
  • Build new Windows apps quickly with robust templates
  • Develop testable and maintainable apps using the MVVM pattern
  • Modernize WPF and WinForms applications with WinUI and XAML Islands
  • Discover how to build apps that can target Windows and leverage the power of the web
  • Install the XAML Controls Gallery sample app and explore available WinUI controls

Who this book is for

This book is for anyone who wants to develop Windows applications with a modern user experience (UX). If you are familiar with UWP and WPF and are looking to enhance your knowledge of Windows development and modernize existing apps, you will find this book useful. Hands-on experience with C# and .NET is expected but no prior knowledge of WinUI is required.

Table of contents

  1. Learn WinUI 3.0
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Section 1: Introduction to WinUI and Windows Applications
  7. Chapter 1: Introduction to WinUI
    1. Technical requirements
    2. Before UWP – Windows 8 XAML applications
      1. Windows application UI design
      2. Windows Runtime (WinRT)
      3. User backlash and the path forward to Windows 10
    3. Windows 10 and UWP application development
      1. Language choice with UWP development
      2. Lifting app restrictions
      3. UWP backward compatibility
    4. What is XAML?
      1. Creating an adaptive UI for any device
      2. Powerful data binding
      3. Styling your UI with XAML
      4. Separating presentation from business logic
    5. What is WinUI?
      1. The first WinUI release
      2. The road to WinUI 3.0
    6. What's new in WinUI 3.0?
      1. Goodbye UWP?
      2. New features for WinUI 3.0
      3. Project Reunion and WinUI
    7. WinUI compared to other Windows development frameworks
      1. WinUI versus UWP
      2. WinUI versus WPF
      3. WinUI versus Windows Forms (WinForms)
    8. Summary
    9. Questions
  8. Chapter 2: Configuring the Development Environment and Creating the Project
    1. Technical requirements
    2. Installing Visual Studio and Windows development workloads
      1. Adding the WinUI app templates
    3. Introducing the application idea
      1. Reviewing the application features
      2. WinUI in UWP versus WinUI in Desktop projects
    4. Creating your first WinUI project
    5. Anatomy of a WinUI in UWP project
      1. Reviewing App.xaml
      2. Reviewing App.xaml.cs
      3. Reviewing MainPage.xaml
      4. Reviewing MainPage.xaml.cs
      5. Reviewing the project references
      6. Reviewing the project properties
    6. XAML basics
      1. Building the model
      2. Creating sample data
      3. Building the initial UI
      4. Completing the data-binding initialization
      5. Creating the DataTemplate and binding the UI
    7. Understanding WinUI and UWP
      1. Understanding the UWP app model
    8. Working with WinUI controls, properties, and events
      1. Adding a ListView header
      2. Creating the ComboBox filter
      3. Adding a new item button
    9. Summary
    10. Questions
  9. Chapter 3: MVVM for Maintainability and Testability
    1. Technical requirements
    2. Understanding MVVM
      1. MVVM – the big picture
    3. MVVM libraries for WinUI
      1. Windows Community Toolkit MVVM library
      2. Prism Library
      3. MVVMCross
      4. Choosing a framework for WinUI applications
    4. Understanding data binding in WinUI
      1. What are markup extensions?
      2. Binding markup extension
      3. x:Bind markup extension
      4. Updating View data with INotifyPropertyChanged
      5. Updating collection data with INotifyCollectionChanged
    5. Implementing MVVM in WinUI applications
    6. Working with events and commands
      1. Implementing ICommand
      2. Using commands in the ViewModel
      3. Updating the View
    7. Choosing a unit test framework
    8. Summary
    9. Questions
  10. Chapter 4: Advanced MVVM Concepts
    1. Technical requirements
    2. Understanding the basics of DI
    3. Using DI with ViewModel classes
    4. Leveraging x:Bind with events
    5. Page navigation with MVVM and DI
      1. Adding ItemDetailsPage
      2. Adding new interfaces and services
      3. Creating a navigation service
      4. Creating a data service
      5. Increasing maintainability by consuming services
      6. Handling parameters in ItemDetailsPage
      7. Creating the ItemDetailsViewModel class
    6. Summary
    7. Questions
  11. Chapter 5: Exploring WinUI Controls
    1. Technical requirements
    2. Understanding what WinUI offers developers
      1. Animated visual player (Lottie)
      2. Navigation view
      3. Parallax view
      4. Rating control
      5. Two-pane view
    3. Exploring the XAML Controls Gallery Windows app
      1. Learning about the ScrollViewer control
    4. Reviewing what's new in WinUI 3.0
      1. Backward compatibility
      2. Visual Studio tooling
      3. Input validation
      4. A new WebView
    5. Exploring the XamlDirect APIs for middleware authors
    6. Adding some new controls to the project
      1. Using the SplitButton control
      2. Adding a TeachingTip to the save button
    7. Summary
    8. Questions
    9. Further reading
  12. Chapter 6: Leveraging Data and Services
    1. Technical requirements
    2. Managing application state with app life cycle events
      1. Exploring Windows application life cycle events
      2. Life cycle events of WinUI applications
    3. Creating a SQLite data store
      1. What is SQLite?
      2. Adding SQLite to DataService
      3. Leveraging a Micro ORM to simplify data access
      4. Adding Dapper to the project
      5. Updating the data service's initialization
    4. Retrieving data via services
    5. Performing data validation with MVVM
    6. Summary
    7. Questions
  13. Section 2: Extending WinUI and Modernizing Applications
  14. Chapter 7: Fluent Design System for Windows Applications
    1. Technical requirements
    2. What is the Fluent Design System?
      1. Exploring Fluent Design for Windows
      2. Controls
      3. Patterns
      4. Layout
      5. Input
      6. Style
    3. Incorporating Fluent Design in WinUI applications
      1. Updating the title bar
      2. Changing the style of MainPage
      3. Changing the style of ItemDetailsPage
    4. Using the Fluent XAML Theme Editor
      1. Colors
      2. Shapes
    5. Using the UWP Resources Gallery
    6. Design resources and toolkits for Fluent Design
    7. Summary
    8. Questions
  15. Chapter 8: Building WinUI Apps with .NET 5
    1. Technical requirements
    2. Creating a WinUI project with .NET 5
      1. What is WinUI in Desktop?
      2. Creating a new WinUI in Desktop project
    3. Exploring the Desktop project structure
      1. Adding the WebView2 control
    4. Exploring the Packaging project
      1. Visual assets in the Manifest Designer
    5. Referencing .NET 5 Libraries from your project
    6. Sharing the .NET 5 library with a WPF application
    7. Creating a WinUI control library
    8. Summary
    9. Questions
  16. Chapter 9: Enhancing Applications with the Windows Community Toolkit
    1. Technical requirements
    2. Introducing the WCT
      1. Origins of the WCT
      2. Reviewing recent toolkit releases
    3. Exploring the Windows Community Toolkit Sample App
      1. Installing and launching the sample app
      2. Controls
      3. WPF and WinForms controls
    4. Using controls from the toolkit
      1. Creating the WinUI in Desktop project
      2. Referencing the WCT packages
      3. Adding data to the DataGrid
      4. Adding controls to the MainWindow
    5. Exploring the toolkit's helpers, services, and extensions
      1. Helpers
      2. Services
      3. MVVM
      4. Extensions
    6. Summary
    7. Questions
  17. Chapter 10: Modernizing Existing Win32 Applications with XAML Islands
    1. Technical requirements
    2. What is XAML Islands?
    3. Modernizing a WinForms application with XAML Islands
      1. Creating a shared class library project
      2. Creating the WinForms host project
    4. Modernizing a WPF application with XAML Islands
    5. Using the UWP MapControl in WPF
    6. Using the WebViewCompatible browser control in WPF
    7. Working with the WebView2 browser control in WinForms
    8. Summary
    9. Questions
  18. Section 3: Build and Deploy on Windows and Beyond
  19. Chapter 11: Debugging WinUI Applications with Visual Studio
    1. Technical requirements
    2. Debugging in Visual Studio
      1. Debugging local applications
      2. Debugging remote applications
      3. Common XAML layout mistakes
      4. Improving your XAML with static code analysis
    3. Learning to pinpoint data binding errors
      1. Common mistakes in data binding
      2. Using the XAML Binding Failures window
    4. Debugging live data with Live Visual Tree and Live Property Explorer
      1. Coding with XAML Hot Reload
      2. Debugging with Live Visual Tree and Live Property Explorer
    5. Summary
    6. Questions
  20. Chapter 12: Hosting an ASP.NET Core Blazor Application in WinUI
    1. Technical requirements
    2. Getting started with ASP.NET Core and Blazor
      1. Exploring some history of ASP.NET and ASP.NET Core
      2. What is Blazor?
      3. WebAssembly and client-side .NET development
    3. Creating a Blazor Wasm application
      1. Building a simple application for tracking tasks
    4. Exploring Blazor Wasm deployment options
      1. Deployment options for Blazor Wasm projects
    5. Publishing Blazor to Azure Static Web Apps hosting
      1. Pushing the project to GitHub
      2. Creating an Azure Static Web Apps resource
      3. Publishing an application with GitHub Actions
    6. Hosting your Blazor application in the WinUI WebView2
    7. Summary
    8. Questions
  21. Chapter 13: Building, Releasing, and Monitoring Applications with Visual Studio App Center
    1. Technical requirements
    2. Getting started with Visual Studio App Center
      1. Creating an App Center account
      2. Creating your first App Center application
    3. Setting up builds in App Center
      1. Integrating App Center with a GitHub repository
    4. Deploying your application with App Center
      1. Creating early releases of your application or beta testers
    5. Application monitoring and analytics
      1. Instrumenting your code
    6. Gathering and analyzing App Center crash reports
    7. Summary
    8. Questions
  22. Chapter 14: Packaging and Deploying WinUI Applications
    1. Technical requirements
    2. Discovering application packaging and MSIX basics
      1. What is MSIX?
      2. Reviewing MSIX tools and resources
    3. Getting started with application packaging in Visual Studio
    4. Deploying applications with Windows Package Manager
      1. Adding a package to the community repository
      2. Using WinGet for package management
    5. Distributing applications with the Microsoft Store
      1. Preparing a free application for the Microsoft Store
      2. Uploading a package to the Store
    6. Sideloading WinUI applications with MSIX
      1. Creating an MSIX package for sideloading
      2. Sideloading an MSIX package
    7. Summary
    8. Questions
  23. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Why subscribe?
  24. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think

Product information

  • Title: Learn WinUI 3.0
  • Author(s): Alvin Ashcraft
  • Release date: March 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800208667