Windows Phone 7.5 Data Cookbook - Ramesh Thalli - E-Book

Windows Phone 7.5 Data Cookbook E-Book

Ramesh Thalli

0,0
31,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Windows Phone 7.5 Mango contains support for apps written in Silverlight or XNA. These apps can store data on the device, and also load and manipulate data from "the cloud" and other web services.This Windows Phone 7.5 Data Cookbook has a range of recipes to help you apply data handling concepts. You will be able to apply the knowledge gained from these recipes to build your own apps effectively. This Windows Phone 7.5 Data Cookbook starts with data binding concepts at the UI layer and then shows different ways of saving data locally and externally in databases. The book ends with a look at the popular MVVM software design pattern. The recipes contained in this book will make you an expert in the areas of data access and storage.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 175

Veröffentlichungsjahr: 2011

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Windows Phone 7.5 Data Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Data Binding to UI Elements
Introduction
Element binding
Getting ready
How to do it...
How it works...
There's more...
See also
DataContext
Getting ready
How to do it…
How it works...
There's more...
How to export the project as a template
See also
Data Templates
Getting ready
How to do it...
How it works...
There's more...
See also
How DataMode is used
Getting ready
How to do it...
How it works...
There's more...
See also
Converting data for display
Getting ready
How to do it...
How it works...
There's more...
See also
Building a simple app
Getting ready
How to do it...
How it works...
There's more...
See also
2. Isolated Storage
Introduction
Saving user settings
Getting ready
How to do it...
How it works...
There's more...
See also
Opening and creating a file
Getting ready
How to do it...
How it works...
There's more...
See also
Saving username and password to a local store
Getting ready
How to do it...
How it works...
There's more...
See also
Saving a background image to local storage
Getting ready
How to do it...
How it works...
There's more...
See also
3. XML as a Data Store
Introduction
Opening a local XML file
Getting ready
How to do it...
How it works...
There's more...
Parsing XML using the XmlReader class
See also
Navigating the XML file
Getting ready
How to do it…
How it works...
There's more...
See also
Opening a remote XML file
Getting ready
How to do it…
How it works...
There's more...
See also
Object serialization to XML
Getting ready
How to do it...
How it works...
There's more...
See also
4. Using Open Data
Introduction
Consuming OData services
Getting ready
How to do it...
How it works...
There's more...
Using Reference to create the proxy class
See also
Searching OData services
Getting ready
How to do it...
How it works...
There's more...
Different parameters supported by Netflix OData
See also
CRUD operations with OData
Getting ready
How to do it...
How it works...
There's more...
OData Explorer
See also
5. Using On-Device Databases
Introduction
Overview of SQLite Studio
Getting ready
How to do it...
How it works...
There's more...
See also
SQLite Client as an embedded database
Getting ready
How to do it...
How it works...
There's more...
See also
Using SQLite as a local store for the MyTasks App
Getting ready
How to do it...
How it works...
See also
SQL CE as a local store
Getting ready
How to do it...
How it works...
There's more...
Creating and deleting data in SQL CE using LINQ to SQL
See also
McObject Perst as an embedded object database
Getting ready
How to do it...
How it works...
There's more...
See also
6. Representational State Transfer—REST
Introduction
Consuming RSS Feeds
Getting ready
How to do it...
How it works...
There's more...
See also
Using the Twitter API
Getting ready
How to do it...
How it works...
There's more...
See also
Building a simple REST service
Getting ready
How to do it...
How it works...
There's more...
See also
7. Windows Communication Framework—WCF
Introduction
Writing and consuming a simple web service
Getting ready
How to do it...
How it works...
There's more...
See also
Building a service layer using WCF
Getting ready
How to do it...
How it works...
There's more...
See also
WCF using ADO.NET Entity Framework
Getting ready
How to do it...
How it works...
There's more...
See also
Using LINQ to SQL for creating the service
Getting ready
How to do it...
How it works...
There's more...
See also
8. Model View ViewModel
Introduction
Simple MVVM application
Getting ready
How to do it...
How it works...
There's more...
How to use the project template
See also
Using MVVM Light Toolkit
Getting ready
How to do it...
How it works...
There's more...
See also
Updating the MVVM application
Getting ready
How to do it...
How it works...
There's more...
Multiple Views with the same ViewModel
See also
Index

Windows Phone 7.5 Data Cookbook

Windows Phone 7.5 Data Cookbook

Copyright © 2011 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 author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.

First published: October 2011

Production Reference: 1181011

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-84969-122-2

www.packtpub.com

Cover Image by Asher Wishkerman (<[email protected]>)

Credits

Author

Ramesh Thalli

Reviewers

John Baird

Feyaerts David

Atley Hunter

Ian T. Lackey

Acquisition Editor

Steven Wilding

Development Editors

Gaurav Mehta

Hithesh Uchil

Technical Editor

Llewellyn F. Rozario

Copy Editor

Neha Shetty

Project Coordinator

Kushal Bhardwaj

Proofreader

Chris Smith

Indexer

Hemangini Bari

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

Ramesh Thalli is a Senior Application Architect and a developer who has over 15 years of experience in the Microsoft Windows development environment. He has worked extensively in WinForms, ASP.NET, WPF, Silverlight, SQL Server and is proficient in C, C++, and C# languages. He has conducted many live and online training workshops in Microsoft technologies. He has a passion for Mobile Operating Systems, which includes iPhone, Android, and WP7.

He specializes in building enterprise applications in IT Support Functions such as Project Portfolio Management, Project Management, HR Systems, IT Governance, Enterprise Architecture, IT Finance, and Software Estimation.

He has extensive experience in the telecom and healthcare insurance industries. In his spare time, he loves to teach and also has a keen interest in exploring world percussion instruments.

First, I would like to thank everyone at Packt Publishing for making this book a reality. Secondly, I would like to thank my wife, Roopa, for believing in me and helping me complete this book successfully. Last, but not the least, I would like to thank my family and friends, in particular Sujeeth Narayan, Gordon Durich, and Shravan Tedla for giving their feedback and encouraging me.

About the Reviewers

John Baird is the founder of XamlWare, a professional consulting firm specializing in Silverlight and Windows Phone 7 development. John has 30 years of experience designing, coding, and implementing software solutions.

John co-founded the Northern Delaware .Net Users group. He is heavily involved in the local .Net communities, and travels extensively giving presentations to user groups, code camps, and special-interest groups.

John is also a four-time recipient of Microsoft's MVP award and is a part of the exclusive group of 23 MVPs chosen to be a Windows Phone 7 MVP.

Feyaerts David has worked on .Net technologies for more than three years. After having completed a Bachelor's degree in Informatique and System, he worked as a software engineer at Bizzdev (Belgium).

He especially works on C# and .Net (mobile and desktop applications), and was quickly promoted to a project leader. He works on multiple projects such as desktop application, mobile application (Windows Mobile and Windows Phone), ASP website, and so on.

To validate his expertise on .Net technologies, he is both a Microsoft Certified Professional Developer (MCPD) and Microsoft Certified Technology Specialist (MCTS) on Silverlight 4.

As a mobile developer for his employer he participates in development of an e-Health application for Windows Phone 7. He appreciates the WP7 platform since it is easy to use and provides new opportunities of design.

During personal time, he also works independently as a developer for Windows Phone applications. At the time of writing, he is working on his fourth application.

Atley Hunter has been a professional developer for over 15 years and was a mobile developer way before it was cool. Atley is constantly pushing devices to do more. As an MVP in Windows Phone Development with over 40 apps under his belt and numerous talks, blog postings, and HackFests, he is continually working to expand his development knowledge and share it with anyone who wants to learn.

When not at the computer or working with other developers, Atley is an avid adventurer and can be found snowboarding, rappelling, bungee jumping, skydiving, base jumping, mountain/rock/structure climbing or kayaking.

Active on LinkedIn (http://www.linkedin.com/in/AtleyHunter), Twitter (http://twitter.com/AtleyHunter), and on his blog (www.atleyhunter.com), Atley is never far from reach and is always happy to help.

Ian T. Lackey worked as a systems engineer for a St. Louis-based ISP from 1999 to 2002. At that time, he began developing web applications using ASP and migrated to ASP.NET shortly before the 2.0 release. Ian now works as a full-time programmer analyst II for the Pediatrics department of Washington University's School of Medicine. He also runs a small business, DigitalSnap Inc. (http://www.digitalsnap.net) that provides custom Silverlight software, individual DotNetNuke modules (http://www.itlackey.net), as well as custom and commercial Windows Phone 7 applications.

Currently Ian is involved in community-driven areas such as the OpenLight Group (http://www.openlightgroup.net), which manages open source projects including several DotNetNuke modules and many Silverlight-based applications. He is also a registered iNeta speaker and is involved with the St. Louis .NET user group (http://www.ineta.org). Ian currently lives in a small town in Illinois, just East of St. Louis, with his wife Julie (http://www.calljulie.info) and two daughters, Britney and Brooklyn.

To everyone in my life, I truly thank you all for the love and support you have so graciously provided throughout the years!

www.PacktPub.com

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. 

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

I like to dedicate this book to my sons, Surya and Pranav, who represent the future gadget generation to whom I would like to pass on the Windows experience.

Preface

Storing and manipulating data plays an important role in making any mobile phone effective in business applications or any other data-driven application. Windows Phone 7.5 Data Cookbook covers topics such as how to bind data easily using databinding techniques, how to save data in local storage for later retrieval, how to format XML for data storage, exploring on-device databases for storage options, how to consume cloud data sources like OData, REST, and WCF, and finally, how to scale applications using the most popular MVVM pattern.

This book has a wide range of simple to complex recipes, which help you understand basic concepts of data handling. You will be able to apply the knowledge you gained from these recipes to build your own apps effectively. Instead of diving into writing complex sample applications for the first time, this book focuses on simplifying the concepts in an easy step-by-step fashion using simple straightforward samples.

Windows Phone 7.5 Data Cookbook will make you an expert in the areas of data access and storage. When you are ready to start developing a data-driven Windows Phone 7 application, you will be well equipped with the different scenarios to implement and store data.

What this book covers

Chapter 1, Databinding to UI Elements, shows how to create data binding to User Interface elements using any data sources such as CLR Objects, files, XML, or external databases. Various topics such as Element Binding, DataContext, DataTemplates, DataMode, and Data Converters are covered. Finally, a simple app is created applying the different databinding concepts.

Chapter 2, Isolated Storage, demonstrates how to open, create, and save user settings to local isolated storage for later consumption, using name/value pairs or images or XML files.

Chapter 3, XML as a Data Store, covers how to open a local or remote XML file, how to navigate the XML file to search for specific information, and finally, how to serialize XML to an object.

Chapter 4, Using Open Data, explains how to consume OData with a simple URI and then how to search with different operations. Finally, it demonstrates how to execute CRUD operations with OData.

Chapter 5, Using On-device Databases, explores different on-device database options available such as commercial Perst, open source SQLite, and Microsoft's SQL CE. It also explains how to use LINQ to SQL in SQL CE.

Chapter 6, Representational State Transfer—REST, covers basic concepts of consuming REST services and calling different social media services such as Twitter and RSS Feeds. Finally, it demonstrates how to build a simple REST service.

Chapter 7, Windows Communication Foundation–WCF, demonstrates how to create and consume simple web services and understand LINQ features. It demonstrates how to build services using ADO.NET Entity Data Model and LINQ to SQL. Both these technologies significantly automate building service layers quickly and effectively.

Chapter 8, Model View ViewModel, introduces us to basic concepts of the MVVM design pattern and how it can be implemented using simple samples. MVVM Light toolkit is introduced by demonstrating different scenarios of applications. Finally, a sample is created to demonstrate how easy it will be to maintain a MVVM-patterned application.

What you need for this book

The following is the list of software needed for this book. Different software and tools are used during the course of this book to demonstrate specific concepts or techniques.

Microsoft Visual Studio 2010 Express for Windows Phone http://www.microsoft.com/visualstudio/en-us/products/2010-editions/windows-phone-developer-toolsMicrosoft Visual Studio Web Developer 2010 Express http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-web-developer-expressSQL Server 2008 Manager Express http://www.microsoft.com/download/en/details.aspx?id=26729SQL CE Edition 4.0 http://go.microsoft.com/fwlink/?LinkId=212219SQLite Studio http://sqlitestudio.one.pl/SQLite Client http://sqlitewindowsphone.codeplex.com/releasesMicrosoft Web Matrix http://www.asp.net/web-pagesPerst.Net http://www.mcobject.comMVVMLight toolkit http://mvvmlight.codeplex.com/Phone 7 toolkit http://silverlight.codeplex.com/releases

Who this book is for

This book is for developers who understand the language features of C#, XAML, and Silverlight technologies, and want to build data-driven apps, or line-of-business (LOB) applications using Windows Mobile platform. It helps if the developer has some understanding of Metro design philosophy and user interface guidelines from Microsoft. Also, this book helps developers of other mobile platforms to convert their apps to Windows Phone 7.

Conventions

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

Code words in text are shown as follows: "First, create a private variable for DataClass before the MainPage constructor."

A block of code is set as follows:

namespace Recipe2 { public class DataClass { public string Name { get; set; } public string Notes { get; set; } } }

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

<TextBlock x:Name="ApplicationTitle" Text="Phone7 Recipes" Style="{StaticResource PhoneTextNormalStyle}"/>

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

datasvcutil /uri:http://services.odata.org/(S(bltvbobia1rthiavqczdcr1u))/OData/OData.svc/ /out:.\EditODataModel.cs /Version:2.0 /DataServiceCollection

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Click on the New Query icon in the tab bar and then Execute the selected query."

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.

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 on 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 all Packt books you have purchased 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.

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 would 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/support, 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright 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

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Data Binding to UI Elements

In this chapter, we will cover:

Element BindingDataContextDataTemplatesHow DataMode is usedConverting data for displayBuilding a Simple App

Introduction

Data binding in Windows Phone 7 is basically connecting the UI Element with any data source. The data source may be a CLR Object, File, XML, RSS/Atom, SQL Server Database, ODATA, or any web service. The data source can reside on either on-device or external sources. Data binding is a powerful feature that makes it easy to tie UI elements to data elements in one simple property.

In this chapter, we will look into different aspects of data binding. In the first recipe we will learn how to declare Binding properties for a textbox element. Then, you will be introduced to DataContext, which is very important for connecting the data to UI elements. DataContext is also very important for separating the View from the Model, which is used in the MVVM (Model-View-ViewModel) pattern. We will learn how DataTemplates make it easy to reuse templates.DataMode helps in setting the Databinding to one way or two way updates. Notification