Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
.NET MAUI Projects - Third Edition

You're reading from  .NET MAUI Projects - Third Edition

Product type Book
Published in Feb 2024
Publisher Packt
ISBN-13 9781837634910
Pages 630 pages
Edition 3rd Edition
Languages
Authors (3):
Michael Cummings Michael Cummings
Profile icon Michael Cummings
Daniel Hindrikes Daniel Hindrikes
Profile icon Daniel Hindrikes
Johan Karlsson Johan Karlsson
Profile icon Johan Karlsson
View More author details

Table of Contents (18) Chapters

Preface 1. Part 1: Introduction
2. Chapter 1: Introduction to .NET MAUI 3. Chapter 2: Building Our First .NET MAUI App 4. Chapter 3: Converting a Xamarin.Forms App into .NET MAUI 5. Part 2: Basic Projects
6. Chapter 4: Building a News App Using .NET MAUI Shell 7. Chapter 5: A Matchmaking App with a Rich UX Using Animations 8. Chapter 6: Building a Photo Gallery App Using CollectionView and CarouselView 9. Chapter 7: Building a Location Tracking App Using GPS and Maps 10. Chapter 8: Building a Weather App for Multiple Form Factors 11. Part 3: Advanced Projects
12. Chapter 9: Setting Up a Backend for a Game Using Azure Services 13. Chapter 10: Building a Real-Time Game 14. Chapter 11: Building a Calculator Using .NET MAUI Blazor 15. Chapter 12: Hot Dog or Not Hot Dog Using Machine Learning 16. Index 17. Other Books You May Enjoy

Building a Weather App for Multiple Form Factors

.NET MAUI isn’t just for creating apps for phones; it can also be used to create apps for tablets and desktop computers. In this chapter, we will build an app that will work on all of these platforms and optimize the user interface for each form factor. As well as using three different form factors, we are also going to be working on four different operating systems: iOS, macOS, Android, and Windows.

The following topics will be covered in this chapter:

  • Using FlexLayout in .NET MAUI
  • Using VisualStateManager
  • Using different views for different form factors
  • Using behaviors

Let’s get started!

Technical requirements

To work on this project, we need to have Visual Studio for Mac or PC installed, as well as the necessary .NET MAUI components. See Chapter 1, Introduction to .NET MAUI, for more details on how to set up your environment. To build an iOS app using Visual Studio for PC, you need to have a Mac connected. If you don’t have access to a Mac at all, you can choose to just work on the Windows and Android parts of this project. Similarly, if you only have a Mac, you can choose to work on only the iOS and Android parts of this project.

You can find the full source for the code in this chapter at https://github.com/PacktPubliching/MAUI-Projects-3rd-Edition.

Project overview

Applications for iOS and Android can run on both phones and tablets. Often, apps are just optimized for phones. In this chapter, we will build an app that will work on different form factors, but we aren’t going to stick to just phones and tablets – we are going to target desktop computers as well. The desktop version will be for Window UI Library (WinUI) and macOS via Mac Catalyst.

The app that we are going to build is a weather app that displays the weather forecast based on the location of the user. For this chapter, we will be referencing Visual Studio for Mac in the instructions. If you are using Visual Studio for Windows, you should be able to follow along. Use one of the other chapters for reference if you need help.

Building the weather app

It’s time to start building the app. Create a new blank .NET MAUI app using the following steps for Visual Studio for Mac:

  1. Open Visual Studio for Mac and click on New:
Figure 8.1 – Visual Studio 2022 for Mac start screen

Figure 8.1 – Visual Studio 2022 for Mac start screen

  1. In the Choose a template for your new project dialog, use the .NET MAUI App template, which is under Multiplatform | App, then click Continue:
Figure 8.2 – New project 

Figure 8.2 – New project 

  1. In the Configure your new .NET MAUI App dialog, ensure the .NET 7.0 target framework is selected, then click Continue:
Figure 8.3 – Choosing the target framework

Figure 8.3 – Choosing the target framework

  1. In the Configure your new .NET MAUI App dialog, name the project Weather, then click Create:
Figure 8.4 – Naming the new app

Figure 8.4 – Naming the new app

If you run the app now, you should see something like the following:

Figure 8.5 – Weather app on macOS
...

Summary

In this chapter, we successfully created an app for four different operating systems – iOS, macOS, Android, and Windows – and three different form factors – phones, tablets, and desktop computers. To create a good user experience on all platforms and form factors, we used FlexLayout and VisualStateManager. We also learned how to handle different views for different form factors, as well as how to use Behaviors.

The next app we will build will be a game with real-time communication. In the next chapter, we will take a look at how we can use the SignalR service in Azure as the backend game service.

lock icon The rest of the chapter is locked
You have been reading a chapter from
.NET MAUI Projects - Third Edition
Published in: Feb 2024 Publisher: Packt ISBN-13: 9781837634910
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}