Book Image

Windows Application Development Cookbook

By : Marcin Jamro
Book Image

Windows Application Development Cookbook

By: Marcin Jamro

Overview of this book

Need to ensure you can always create the best Windows apps regardless of platform? What you need are solutions to the biggest issues you can face, so you can always ensure you’re making the right choices and creating the best apps you can. The book starts with recipes that will help you set up the integrated development environment before you go ahead and design the user interface. You will learn how to use the MVVM design pattern together with data binding, as well as how to work with data in different file formats. Moving on, you will explore techniques to add animations and graphics to your application, and enable your solution to work with multimedia content. You will also see how to use sensors, such as an accelerometer and a compass, as well as obtain the current GPS location. You will make your application ready to work with Internet-based scenarios, such as composing e-mails or downloading files, before finally testing the project and submitting it to the Windows Store. By the end of the book, you will have a market-ready application compatible across different Windows devices, including smartphones, tablets, and desktops.
Table of Contents (17 chapters)
Windows Application Development Cookbook
Credits
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
Preface

Preface

Nowadays, there are various types of devices available on the market, such as smartphones, tablets, and desktops. You can use them every day to perform common tasks, such as browsing the Internet, sending e-mail messages, recording movies, sharing photos using social media, and playing games. It is not unusual to use even more than one device, for instance, a smartphone, which we carry in our pockets almost all the time, a tablet that we use to perform various tasks at home, and a desktop at work. Of course, these devices can differ significantly from each other not only in terms of screen resolution, but also about available sensors and performance. However, does it mean that you cannot develop your own application for all of them in a simple way? Do you need to create a separate application from scratch for smartphones, tablets, and desktops?

If such devices use the Windows 10 operating system, the answer to both these questions is no! This platform allows you to develop a Universal Windows Platform (UWP) application that can be run on various device families. Such a task is really simplified because you can use the same programming language, technologies, as well as the Integrated Development Environment (IDE).

Despite supporting a wide range of devices, the UWP applications can be equipped with an attractive User Interface (UI) created using the Extensible Application Markup Language (XAML). With the availability of a set of predefined controls and animations, your work can be significantly reduced. What is more, you can take advantage of the Model - View - ViewModel (MVVM) design pattern  and data binding to improve quality of the code and make its maintenance easier. The UWP applications can also use multimedia, read data from built-in sensors, and store data in various ways. Internet-based scenarios are supported and you can also download a file or get data from an Application Programming Interface (API). Many devices allow obtaining the current Global Positioning System (GPS) location, which can be used to show a marker in a suitable place on the map or to launch the GPS-based navigation. When the solution is developed, it can be submitted to the Windows Store. Thus, it can be downloaded and used by people all over the world!

Are you ready to learn how to develop an application for Windows 10-based smartphones, tablets, and desktops? If so, let’s start reading and writing the code!

What this book covers

Chapter 1, Getting Started , presents setting up a suitable IDE, creating a project, adding pages to the application, designing a user interface, and handling navigation. You will learn how to run the application in an emulator and on a real device as well as how to debug it and measure performance.

Chapter 2, Designing a User Interface , shows how to design pages using various controls, such as textboxes and buttons, as well as how to arrange them in various variants, either vertically, horizontally, or in a grid. You will also get to know how to prepare user controls, apply styles, localize the project, and prepare dedicated versions of pages for various device families.

Chapter 3, MVVM and Data Binding , covers the application of the MVVM design pattern, which divides the project into three parts, namely, model, view, and view model. The topic of the data binding mechanism, together with commands, is also taken into account. You will see how to display a collection of items and how to use value converters.

Chapter 4, Data Storage , deals with managing directories and files along with writing and reading a few types of files, such as with plain text, XML, and JSON-formatted content, as well as binary files with content in the user-defined format. You will also learn how to use a SQLite database in your application.

Chapter 5, Animations and Graphics , explains how to improve the user interface by introducing animations. They can be applied to display a control as well as change its size, position, or even rotation. This chapter also shows how to handle a few touch events and introduces the topic of rendering 3D graphics using DirectX, XAML, and C++ language.

Chapter 6, Multimedia , describes how to support multimedia content in an application, such as by playing a movie clip, listening to an audio file, and presenting a collection of photos. The subject of modifying images in a programmatic way is also taken into account. You will see how to take an image or record a movie using a camera, scan QR codes, and synthesize and recognize speech.

Chapter 7, Built-in Sensors , presents how to use various sensors to obtain a set of data, such as G-force values using an accelerometer, a heading of magnetic north using a compass, a current value of ambient light using a light sensor, as well as a current orientation of a device. To add to this, you will learn how to control vibrations of a phone and how to obtain the current GPS location.

Chapter 8, Internet-based Scenarios , covers various scenarios related to the Internet, such as opening a website, composing an e-mail message, as well as opening a map in the external tool and directly in your application. You will also see how to get and send some data to an API, as well as how to download files from the Internet.

Chapter 9, Testing and Submission , introduces unit testing and the process of configuring and submitting the project to the Windows Store. You will get to know how to adjust the configuration, prepare the necessary files, submit and update the application, as well as browse reviews and ratings regarding the published application.

What you need for this book

This book presents development of UWP applications for various devices running on the Windows 10 operating system. Thus, you need a set of tools that allow designing the user interface, writing supporting code, as well as running the application and testing it. Fortunately, all of these features are available in the Microsoft Visual Studio Community 2015, which you can use while reading this book. The process of its installation and configuration is presented in detail in Chapter 1, Getting Started .

To step through all recipes presented in this book, especially to publish an application in the Windows Store, it is necessary to have a developer account. What is more, it is recommended to have a real smartphone or tablet with the Windows 10 operating system to test the developed applications on a real device. If you do not have one, you can use the built-in emulators, but not all recipes can be checked in practice.

Who this book is for

The book is dedicated to programmers with various experience in developing applications for Windows-based smartphones, tablets, and desktops. Thus, even beginners can find suitable content to learn how to develop their first application!

However, it is recommended to have some basic knowledge of the C# language and object-oriented programming to understand code snippets presented in the book. Prior experience in developing mobile and desktop applications and using the XAML language is not necessary.

This book is organized in the form of solution-based recipes to present various features that could be interesting for developers. To make it even more useful, the code is attached to each chapter. Thus, you can easily download the code and run the application without the need of typing the code on your own.

It is worth mentioning that some code has been simplified. For this reason, it could differ from the best practices and may have significantly limited, or even removed, security checks and functionalities. Before publishing your application, it should be thoroughly tested to ensure that is works correctly in various circumstances.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The files regarding the default page, both .xaml and .xaml.cs, are automatically added to the main directory."

A block of code is set as follows:

    private void button_Click(object sender, RoutedEventArgs e) 
    { 
        Frame.Navigate(typeof(ProductsPage), 0); 
    }

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

    private void button_Click(object sender, RoutedEventArgs e) 
    { 
        if (Frame.CanGoBack) 
        { 
            Frame.GoBack(); 
        } 
    }

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Verify a list within the Selected features group and click on Install."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book--what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Windows-Application-Development-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/WindowsApplicationDevelopmentCookbook_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.