Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Creating Cross-Platform C# Applications with Uno Platform: Build apps with C# and XAML that run on Windows, macOS, iOS, Android, and WebAssembly
Creating Cross-Platform C# Applications with Uno Platform: Build apps with C# and XAML that run on Windows, macOS, iOS, Android, and WebAssembly
Creating Cross-Platform C# Applications with Uno Platform: Build apps with C# and XAML that run on Windows, macOS, iOS, Android, and WebAssembly
Ebook461 pages2 hours

Creating Cross-Platform C# Applications with Uno Platform: Build apps with C# and XAML that run on Windows, macOS, iOS, Android, and WebAssembly

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Developers are increasingly being asked to build native applications that run on multiple operating systems and in the browser. In the past, this would have meant learning new technologies and making multiple copies of an application. But the Uno Platform allows you to use tools, languages, and APIs you already know from building Windows apps to develop apps that can also run on other platforms. This book will help you to create customer-facing as well as line-of-business apps that can be used on the device, browser, or operating system of your choice.
This practical guide enables developers to put their C# and XAML knowledge to work by writing cross-platform apps using the Uno Platform. Packed with tips and practical examples, this book will help you to build applications for common scenarios. You'll begin by learning about the Uno Platform through step-by-step explanations of essential concepts, before moving on to creating cross-platform apps for different lines of business. Throughout this book, you'll work with examples that will teach you how to combine your existing knowledge to manage common development environments and implement frequently needed functionality.
By the end of this Uno development book, you will have learned how to write your own cross-platform apps with the Uno Platform and use additional tools and libraries to speed up your app development process.

LanguageEnglish
Release dateAug 27, 2021
ISBN9781801070867
Creating Cross-Platform C# Applications with Uno Platform: Build apps with C# and XAML that run on Windows, macOS, iOS, Android, and WebAssembly
Author

Matt Lacey

Matt Lacey is an independent mobile developer and consultant and a Microsoft MVP. He's built, advised on, and contributed to apps for social networks, film and TV broadcasters, travel companies, banks and financial institutions, sports companies, news organizations, music-streaming services, device manufacturers, and electronics retailers. These apps have an installed base of more than 500,000,000 users and are used every day around the world. Matt previously worked at a broad range of companies, doing many types of development. He has worked at startups, small ISVs, national enterprises, and global consultancies, and written software for servers, desktops, devices, and industrial hardware in more languages than he can remember. He lives in the UK with his wife and two children.

Related to Creating Cross-Platform C# Applications with Uno Platform

Related ebooks

Programming For You

View More

Related articles

Reviews for Creating Cross-Platform C# Applications with Uno Platform

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Creating Cross-Platform C# Applications with Uno Platform - Matt Lacey

    Cover.png

    BIRMINGHAM—MUMBAI

    Creating Cross-Platform C# Applications with Uno Platform

    Copyright © 2021 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 Group Product Manager: Pavan Ramchandani

    Publishing Product Manager: Rohit Rajkumar

    Senior Editor: Sofi Rogers

    Content Development Editor: Feza Shaikh

    Technical Editor: Saurabh Kadave

    Copy Editor: Safis Editing

    Project Coordinator: Manthan Patel

    Proofreader: Safis Editing

    Indexer: Subalakshmi Govindhan

    Production Designer: Vijay Kamble

    First published: September 2021

    Production reference: 1250821

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham

    B3 2PB, UK.

    978-1-80107-849-8

    www.packt.com

    Contributors

    About the authors

    Matt Lacey has been building desktop and mobile software since the '90s. He currently works as an independent development consultant and focuses on helping developers to create better software. Having worked in companies of all sizes and in a wide variety of industries, he brings this breadth of experience to present a viewpoint that considers technology, business, and design.

    Matt is a Microsoft MVP in Windows Development, regularly speaks at user groups and conferences in multiple countries, and is a prolific contributor to a plethora of open source projects. He lives in the UK with his wife and two children.

    Marcel Alexander Wagner is a full-stack software developer and open source contributor. He is a Microsoft MVP in Windows Development and a top contributor to the WinUI library and the XAML Controls Gallery, while also contributing to other projects and libraries, including the Windows Community Toolkit and Uno Platform.

    Marcel graduated with a Bachelor of Science in computer science and has since been developing applications and services with a wide variety of technologies, including React, Java, C#, C++, UWP, and Uno Platform. He currently resides in Germany.

    About the reviewers

    David Oliver is an open source framework developer with a .NET background. He is a recovering physicist and lapsed Australian. He is currently a senior developer on the Uno Platform core team.

    Martin Zikmund is a freelance software developer and Microsoft Developer Technologies MVP. He specializes in building cross-platform mobile and cloud solutions on the Microsoft technology stack. His passion is contributing to open source, especially to Uno Platform. You can also encounter him on Stack Overflow, where he frequently helps other developers. To document his developer journey, Martin regularly writes articles on his blog and tweets about interesting things he comes across. In his spare time, he likes to play squash, game on Xbox, read, and search for geocaches.

    Nick Randolph currently runs Built to Roam, which focuses on building rich mobile applications. He has been identified as a Microsoft MVP in recognition of his work and expertise with Microsoft application platforms.

    Nick is an active contributor in the device application development space via his blog. He has been invited to present at a variety of events, including TechEd and Ignite Australia and NZ, DDD, NDC, and local user groups. He has also authored multiple books on Visual Studio and Windows development.

    Shimmy Weitzhandler is a skilled full-stack developer and consultant working independently.

    He has been coding for nearly two decades, and has used technologies ranging from ASP.NET, HTML, and JavaScript with VB.NET to WPF, Silverlight, WinUI, and, for the past few years, Uno Platform.

    Among his projects are an emergency response system, a club card management and points accumulation portal, video conversion software, a school and college system, e-commerce websites, and QuickBooks components.

    Shimmy is an active member and contributor on key tech hubs such as GitHub and Stack Overflow.

    He is well known for his distinct programming style, his architectural thinking, and his dedication to creativity and transparency, utilizing the latest technologies.

    Table of Contents

    Preface

    Section 1: Getting to Know Uno Platform

    Chapter 1: Introducing Uno Platform

    Technical requirements

    Understanding what Uno Platform is

    A brief history of Uno Platform

    How Uno Platform works

    Is it a panacea?

    Using Uno Platform

    Uno Platform allows you to use what you already know

    Uno Platform supports many platforms

    Can Uno Platform do everything that your app requires?

    How does Uno Platform compare to the alternatives?

    Setting up your development environment

    Developing with Visual Studio

    Using other editors and IDEs

    Checking your setup

    Debugging your setup

    Summary

    Further reading

    Chapter 2: Writing Your First Uno Platform App

    Technical requirements

    Creating your first app

    Creating your project with the Uno Platform solution templates

    Creating your project with the .NET CLI

    Project structure and the heads

    Building and running your first Uno Platform app

    Running and debugging your app with Visual Studio on Windows

    Running and debugging your apps with Visual Studio for Mac

    Debugging the WASM head of your app

    XAML Hot Reload and C# Edit and Continue

    Platform-specific XAML and C#

    Platform-specific C#

    Platform-specific XAML

    Going beyond the default cross-platform app structure

    The multi-platform library project type

    Other project types

    Summary

    Section 2: Writing and Developing Uno Platform Apps

    Chapter 3: Working with Forms and Data

    Technical requirements

    Introducing the app

    Creating the app

    Entering and validating data

    Using Windows Community Toolkit controls

    Displaying data using DataGrid

    Displaying data with the DataGrid control

    Exporting issues in PDF format

    Exporting on desktop

    Exporting on the web with a download link

    Summary

    Chapter 4: Mobilizing Your App

    Technical requirements

    Introducing the app

    Creating the app

    Creating the main page

    Showing upcoming arrival details

    Retrieving remote data

    Connecting to a remote data source

    Using Polly to handle exceptions and retry requests

    Making your app look like it belongs on each platform

    Applying Material styles to the Android version of the app

    Applying Cupertino styles to the iOS version of the app

    Accessing device capabilities

    Summary

    Chapter 5: Making Your App Ready for the Real World

    Technical requirements

    Introducing the app

    Creating the app

    Creating the main navigation and booking process

    Persisting data locally using the ApplicationData API and SQLite

    Storing data using the ApplicationData API

    Using SQLite to store data

    Loading data from SQLite

    Making your app ready for customers

    Localizing your app

    Customizing your app's appearance

    Ensuring everyone can use your app

    Summary

    Chapter 6: Displaying Data in Charts and with Custom 2D Graphics

    Technical requirements

    Introducing the app

    Creating the app

    Creating the individual pages

    Creating the main page

    Displaying charts with controls from SyncFusion

    Updating references to include the SyncFusion controls

    Drawing a line chart

    Displaying charts with controls from Infragistics

    Updating references

    Drawing a column chart

    Drawing custom graphics with SkiaSharp

    Updating project references

    Drawing the network map

    Responding to changes in the UI

    Changing the page layout

    Stretching and scaling content to fit the available space

    Summary

    Section 3: Test, Deploy, and Contribute

    Chapter 7: Testing Your Apps

    Technical requirements

    Getting started with Uno.UITest

    Writing and running your first test

    How Uno.UITest works

    Authoring your first test

    Running your tests on Android, iOS, and WASM

    Writing more complex tests

    Test tools beside Uno.UITest

    Testing the UWP head of your app with WinAppDriver

    Writing unit tests for your Uno Platform app

    Performing manual testing and why it is important

    Summary

    Chapter 8: Deploying Your Apps and Going Further

    Technical requirements

    Bringing Xamarin.Forms apps to WebAssembly

    Deploying a Wasm Uno Platform app to the web

    Automating build, tests, and distribution

    Deploying your app to a store

    Engaging with the Uno Platform community

    Sources of information

    Sources of help

    Contributing

    Summary

    Other Books You May Enjoy

    Preface

    Developers are increasingly being asked to build native applications that run on multiple operating systems and in the browser. In the past, this would have meant learning new technologies and making multiple copies of an application. But Uno Platform allows you to use tools, languages, and APIs you already know from building Windows apps to develop apps that can also run on other platforms. This book will help you to create customer-facing as well as line-of-business apps that can be used on the device, browser, or operating system of your choice.

    This practical guide enables developers to put their C# and XAML knowledge to work by writing cross-platform apps using Uno Platform. Packed with tips and practical examples, this book will help you to build applications for common scenarios. You'll begin by learning about Uno Platform through step-by-step explanations of essential concepts, before moving on to creating cross-platform apps for different lines of business. Throughout this book, you'll work with examples that will teach you how to combine your existing knowledge to manage common development environments and implement frequently needed functionality.

    By the end of this Uno Platform development book, you will have learned how to write your own cross-platform apps with Uno Platform and use additional tools and libraries to speed up your app development process.

    Who this book is for

    This book is for developers who are familiar with app development for Windows and want to use their existing skills to build cross-platform apps. Basic knowledge of C# and XAML is required to get started with this book. Anyone with basic experience of app development using WPF, UWP, or WinUI will be able to learn how to create cross-platform applications with Uno Platform.

    What this book covers

    Chapter 1, Introducing Uno Platform, introduces the Uno Platform, explaining what it is designed for and when to use it. After this, the chapter will cover how to set up the development machine and install the necessary tools.

    Chapter 2, Writing Your First Uno Platform App, walks through creating your first Uno Platform app and covers the app's structure. By the end of this chapter, you will have written a small Uno Platform app that can be run on different platforms and display content based on the OS the app is running on.

    Chapter 3, Working with Forms and Data, walks you through developing a data-focused line-of-business app for the fictional company UnoBookRail. The chapter covers displaying data, providing input validation on forms, and exporting data to PDF.

    Chapter 4, Mobilizing Your App, introduces you to developing mobile apps using Uno Platform. In addition to that, the chapter covers working with remote data on devices with unstable internet connections, styling the app based on the platform it is running on, and using device capabilities such as the camera.

    Chapter 5, Making Your App Ready for the Real World, covers writing a mobile app that is aimed at external customers. As part of this, it covers persisting data locally on the device, localizing your app, and writing an accessible app with Uno Platform.

    Chapter 6, Displaying Data in Charts and with Custom 2D Graphics, explores displaying graphs and charts in an Uno Platform app. The chapter covers using libraries such as SyncFusion and creating custom graphics using SkiaSharp. Lastly, the chapter covers writing a UI that responds to changes in screen size.

    Chapter 7, Testing Your Apps, introduces you to UI testing with Uno.UITest. In addition, this chapter covers writing automated UI tests with WinAppDriver, writing unit tests for the Windows 10 version of the app, and testing the app for accessibility.

    Chapter 8, Deploying Your Apps and Going Further, walks you through bringing your Xamarin.Forms app to the web with Uno Platform and deploying WASM Uno Platform apps to Azure. After this, the chapter covers deploying an Uno Platform app and joining the Uno Platform community.

    To get the most out of this book

    In this book, we will be using Visual Studio 2019 on Windows 10 and the .NET CLI to develop Uno Platform apps. We will cover installing the necessary extensions and CLI tools; however, installing Visual Studio and the .NET CLI will not be covered. To install the required software, you will need a functional internet connection.

    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/Creating-Cross-Platform-C-Sharp-Applications-with-Uno-Platform. 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!

    Code in Action

    The Code in Action videos for this book can be viewed at https://bit.ly/3yHTfYL

    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/9781801078498_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: Inside the UnoAutomatedTestsApp folder, create a folder named UnoAutomatedTestsApp.UITests.

    A block of code is set as follows:

    private void ChangeTextButton_Click(object sender,

                                        RoutedEventArgs e)

    {

        helloTextBlock.Text = Hello from code behind!;

    }

    When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    xmlns:skia=using:SkiaSharp.Views.UWP

    PaintSurface=OnPaintSurface />

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

    dotnet new unoapp -o MyApp

    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: Open the Test Explorer by clicking View in the menu bar and clicking on Test Explorer.

    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

    Enjoying the preview?
    Page 1 of 1