Learn WinUI 3 - Second Edition

Book description

Unlock the power of WinUI and supercharge your Windows app development with .NET and C# using this beginner's guide

Key Features

  • Find out how to create modern Windows apps with native UI controls
  • Get to grips with modernizing existing desktop apps with a modern UI
  • Leverage WinUI code to build apps for iOS, Android, the web, and more
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

WinUI 3 takes a whole new approach to delivering Windows UI components and controls and has the ability to deliver the same features across multiple versions of Windows. Learn WinUI 3 is a comprehensive introduction to WinUI and Windows apps for anyone who is new to WinUI and XAML applications.

This updated second edition begins by helping you get to grips with the latest features in WinUI and shows you how XAML is used in UI development. The next set of chapters will help you set up a new Visual Studio environment, develop a new desktop project, incorporate the Model-View-ViewModel (MVVM) pattern in a WinUI project, and develop unit tests for ViewModel commands. Next, you’ll cover the basics of data access from WinUI projects with a step-by-step approach. As you advance, you’ll discover how to leverage the Fluent Design System to design beautiful WinUI applications. You’ll also explore the contents and capabilities of the Windows Community Toolkit and learn how to create cross-platform apps with markup and code from your project using Uno Platform. The concluding chapters will teach you how to build, debug, and deploy apps to the Microsoft Store.

By the end of this book, you’ll have learned how to build WinUI applications from scratch and how to modernize existing desktop apps using WinUI 3 and the Windows App SDK.

What you will learn

  • Discover the latest features of WinUI 3 and learn how to provide product feedback
  • Understand the WinUI project structure and the app lifecycle
  • Use the MVVM pattern in WinUI and discover open source MVVM projects
  • Find out how to create a simple data store to save app data between sessions
  • Get to grips with incorporating the concepts of Fluent Design into a WinUI app
  • Discover how to use push notifications and app notifications in WinUI
  • Reuse WinUI views and view models in a cross-platform Uno Platform app

Who this book is for

This book is for anyone looking to develop applications for Windows with a modern UI. If you’re familiar with Windows desktop app development and want to enhance your knowledge of the latest Windows development techniques, this book is for you. Whether you're starting a new project or planning to modernize your existing Windows apps, this book will provide you with guidance. Hands-on experience with C# and .NET is expected, but no prior knowledge of WinUI or the Windows App SDK is required.

Table of contents

  1. Learn WinUI 3
  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. Conventions used
    6. Get in touch
    7. Share your thoughts
    8. Download a free PDF copy of this book
  6. Part 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
    6. What’s new in WinUI 3?
      1. Goodbye UWP?
      2. New features for WinUI 3 and the Windows App SDK
      3. The Windows App SDK and WinUI
    7. WinUI 3 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 desktop development workloads
    3. Introducing the application idea
      1. Reviewing the application features
      2. WinUI in Desktop projects
    4. Creating your first WinUI project
    5. Anatomy of a WinUI in Desktop project
      1. Reviewing App.xaml
      2. Reviewing App.xaml.cs
      3. Reviewing MainWindow.xaml
      4. Reviewing MainWindow.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 Windows App SDK
      1. Understanding the .NET 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. The MVVM Toolkit
      2. The 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 View Model
      3. Updating the View
    7. Leveraging the MVVM Toolkit
    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. Migrating MainWindow to MainPage
      2. Adding ItemDetailsPage
      3. Adding new interfaces and services
      4. Creating a navigation service
      5. Creating a data service
      6. Increasing maintainability by consuming services
      7. Handling parameters in ItemDetailsPage
      8. 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
    3. Exploring the WinUI 3 Gallery app for Windows
      1. Learning about the ScrollViewer control
    4. Reviewing what’s new in WinUI 3 and the Windows App SDK
      1. Backward compatibility
      2. Fluent UI and modern look and feel
      3. Visual Studio tooling
      4. The WebView2 control
      5. What’s new in the Windows App SDK
    5. Adding some new controls to the project
      1. Using the SplitButton control
      2. Adding a TeachingTip control to the Save button
    6. Summary
    7. Questions
  12. Chapter 6: Leveraging Data and Services
    1. Technical requirements
    2. Managing application state with app lifecycle events
      1. Exploring Windows application lifecycle events
      2. Lifecycle events of WinUI applications
      3. Additional lifecycle events with FrameworkElement objects
    3. Creating a SQLite data store
      1. What is SQLite?
      2. Adding SQLite as a data service
      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. Summary
    6. Questions
  13. Part 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. Acrylic material and the Fluent Design System
    6. Use Mica in WinUI applications
      1. Incorporate Mica into My Media Collection
    7. Design resources and toolkits for Fluent Design
    8. Summary
    9. Questions
  15. Chapter 8: Adding Windows Notifications to WinUI Applications
    1. Technical requirements
    2. Overview of push notifications in the Windows App SDK
      1. Raw push notifications
      2. Cloud-based app notifications
      3. Local app notifications
    3. Using raw push notifications in WinUI applications
    4. Adding Windows app notifications with the Windows App SDK
    5. Summary
    6. Questions
  16. Chapter 9: Enhancing Applications with Community Toolkits
    1. Technical requirements
    2. Introducing the WCT
      1. Origins of the WCT
      2. Reviewing recent toolkit releases
    3. Exploring the WCT Gallery app
      1. Installing and launching the app
      2. Controls
    4. Using controls from the toolkit
      1. Creating the WinUI project
      2. Referencing WCT packages
      3. Adding data to the DataGrid control
      4. Adding controls to the MainWindow control
    5. Exploring the toolkit’s helpers, services, and extensions
      1. Helpers
      2. Extensions
    6. .NET Community Toolkit features
    7. Summary
    8. Questions
  17. Chapter 10: Accelerating App Development with Template Studio
    1. Technical requirements
    2. Overview of Template Studio for WinUI
    3. Starting a new WinUI project with Template Studio
    4. Exploring the code generated by Template Studio
      1. Exploring the Core project
      2. Exploring the main project
      3. Exploring the MSTest project
    5. Template Studio extensions for other UI frameworks
      1. Template Studio for WPF
      2. Template Studio for Uno Platform
    6. Summary
    7. Questions
  18. Part 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. Pinpointing data binding failures
      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 a Blazor Application in WinUI
    1. Technical requirements
    2. Getting started with ASP.NET Core and Blazor
      1. A brief 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: Take Your App Cross-Platform with Uno Platform
    1. Technical requirements
    2. An overview of Uno Platform
    3. Creating your first Uno Platform project
    4. Migrating WinUI XAML markup and code to Uno Platform
      1. Migrating the WinUI project code
      2. Migrating the WinUI XAML views
    5. Running on Android with WSA
    6. Running in the browser with WebAssembly
    7. Summary
    8. Questions
  22. Chapter 14: Packaging and Deploying WinUI Applications
    1. Technical requirements
    2. Discovering application packaging and MSIX basics
      1. MSIX
      2. Reviewing MSIX tools and resources
      3. Packaged applications and application identity
    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. Index
    1. Why subscribe?
  24. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share your thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Learn WinUI 3 - Second Edition
  • Author(s): Alvin Ashcraft
  • Release date: October 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781805120063