Welcome to the Introduction to Windows Phone 8 wiki. In this part of the blog I will add introductory content to Windows Phone 8 development, stuff that’s good to remember but one usually ends up forgetting :).
Files and Data
In order to persist data permanently in your windows phone 8 apps you have different possibilities:
- Installation folder
- That is, the files contained in the app project
- Data store reserved for each app in a user’s phone
- Local folder (Windows 8 API)
- Isolated storage API (Windows Phone 7)
- Media library (for media files)
- Local database
The Settings store provides a very simple and easy way to store data in our apps. The Settings store allows the user to store key-value pairs that will be persisted to the app’s local folder when an app is closed and which will be recreated on app relaunch. It is recommended for storing simple data so as not to affect the app relaunch experience.
In Windows Phone 8 we use the
IsolatedStorageSettings API as depicted below:
1 2 3 4 5 6 7 8 9
Files and Folders
Using WP8 APIs you can also create and access files and folders in your app isolated storage (
Windows Runtime Storage
These are a series of APIs shared with Windows 8. They reside in the
Windows.Storage namespace and can be accessed via the
These two classes provide asynchronous methods and use the TPL library that lets us use the async/await pattern.
1 2 3 4 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
You can use the native SDK command line tools to get access to the isolated storage or the Windows Phone Power Tools which provide a much better experience for exploring the phone isolated storage.
Isolated Storage (Legacy)
In those cases where we want to store large datases or perform query operations on a set of data, windows phone 8 offers the possibility of using a local SQL CE database (.sdf files in isolated storage or install folder that are private to the app).
We can define, create and access the database using
LINQ to SQL.
We create the different tables and columns by using a code first approach using attributes to decorate our domain model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
We define a data context that will represent the Unit Of Work using the
DataContext API and exposing collections of entities through
1 2 3 4 5 6
To access the database at runtime, you will need to first create the database via
DataContext.CreateDatabase() and then perform operations using
LINQ to SQL (remember to call
db.SubmitChanges() to persist changes to the database).
1 2 3 4 5
You can access web services in your windows phone app via HTTP by using the
WebClient for common scenarios or the
HttpWebRequest when you need to have more control of the HTTP requests you send to the server. The problem with these APIs are that they work with callbacks although you can wrap the beginning and ending of calls in Tasks to take advantage of the async/await pattern.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Additionally, you can use the
portable HttpClient, an API that is shared with Windows 8 that provides built-in support for asynchronous operations via Tasks. You will need to install this library via NuGet (
1 2 3 4 5
Windows Phone Integration
Launchers and Choosers
- Windows Phone 8 Development for Absolute Beginners at Microsoft Virtual Academy
- Introduction to Windows Phone 8 – Pluralsight