วันพุธที่ 9 พฤษภาคม พ.ศ. 2555

Code Samples for Windows Phone

Code Samples for Windows Phone

Windows Phone developers can download these code samples and applications, such as Panorama/Pivot Control, Bing Maps, and a unit converter, to experiment with the Windows Phone Application Platform. New samples will be added to this page periodically, so check back often and see what’s new.
You need Windows Phone SDK to run these samples. To download Windows Phone SDK, see Installing the Windows Phone SDK.
This topic includes code samples for the following subjects.
The following code samples are designed to get you started quickly. See your first Silverlight, XNA Framework, and combination applications.
Mini-Browser Sample ScreenshotDownload
C# | VB
Mini-Browser Sample
This sample shows how to use the WebBrowser control in your Windows Phone application. The sample takes a URL from the user and navigates to the given page. The sample also automatically adjusts to portrait and landscape modes. For more information about this sample, see How to: Create Your First Silverlight Application for Windows Phone.
Updated 9/2011
HelloXnaFrameworkScreenshotDownload
C# | VB
Hello XNA Framework Sample
This sample demonstrates how to create a basic XNA Framework application. It demonstrates how to load content, move two graphics around the screen, detect when the graphics collide, and play a sound when a collision occurs. For more information about this sample, see How to: Create Your First XNA Framework Application for Windows Phone.
Updated 9/2011
Silverlight XNA Framework SampleDownload
C# | VB
Silverlight/XNA Framework Sample
This sample combines Silverlight and the XNA Framework into a single Windows Phone application. It demonstrates how to render Silverlight controls and text from the XNA Framework by using the UIElementRenderer class. For more information, see How to: Combine Silverlight and the XNA Framework in a Windows Phone Application.
Updated 9/2011
My Little Teapot SampleDownload
C# | VB
My Little Teapot Sample
This sample combines Silverlight and the XNA Framework into a single Windows Phone application. It includes using a Silverlight storyboard to animate controls and using the Silverlight input system to respond to user gestures. For more information, see How to: Combine Silverlight and the XNA Framework in a Windows Phone Application.
Updated 9/2011
The following code samples demonstrate concepts that are fundamental to Windows Phone application development.
Execution Model SampleDownload
C# | VB
Execution Model Sample
On Windows Phone , only one application runs in the foreground at a time. When the user navigates away from an application, it is typically put into a dormant state which is automatically resumed when the user returns. However, it is possible for an application to be tombstoned or terminated after the user navigates away. This sample illustrates a technique for preserving and restoring UI and application state as the application is activated and deactivated by the operating system. For more information, see Execution Model Overview for Windows Phone.
Updated 9/2011
Backstack sample screenshotDownload
C# | VB
Back Stack Navigation Sample
Learn how to visualize, inspect and modify the navigation history, or back stack, of an application. This is useful for applications that want to modify the default navigation experience of their application to provide the optimal user experience for their customers. This sample uses the new BackStack property and the RemoveBackEntry() method available in Windows Phone OS 7.1. To develop this application step-by-step, see How To: Navigate Using the Back Stack for Windows Phone.
Updated 9/2011
Local Database SampleDownload
C# | VB
Local Database Sample
On Windows Phone OS 7.1, you can use LINQ to SQL to store relational data in a local database that resides in your application’s isolated storage container. This sample is a to-do list application that uses a multi-table local database. Items that appear in the list are added, updated, and deleted from a local database, where they will persist between application launches. For step-by-step information about how to develop this application, see How to: Create a Local Database Application with MVVM for Windows Phone.
Updated 9/2011
WeatherForecastSampleScreenshotDownload
C# | VB
Weather Forecast Sample
This sample shows how you can call and process data from a Web Service in a Windows Phone application. The sample calls a web service to get weather forecast information, parses the returned XML, and displays the information in a Weather Forecast page.
Updated 9/2011
Tic Tac Toe Over Sockets SampleDownload
C# | VB
Tic-Tac-Toe Over Sockets Sample
This sample demonstrates the use of sockets on a Windows Phone device to communicate with a service hosted on the network. It uses the new System.Net.Sockets class available on Windows Phone. For more information, see Sockets for Windows Phone.
Updated 9/2011
Multicast Sample ScreenshotDownload
C# | VB
Multicast Sockets Sample
This sample demonstrates how to communicate over a multicast group on a Windows Phone. It implements the classic Rock Paper Scissors game. Players join a multicast group to discover each other. UDP unicasting is then used to challenge a player and play the actual game. The UdpAnySourceMulticastClient class available in Windows Phone OS 7.1 is used in this sample. For more information, see How to: Send and Receive Data in a Multicast Group for Windows Phone.
Updated 9/2011
Network and Device Info Sample ScreenshotDownload
C# | VB
Network and Device Information Sample
This sample demonstrates how you can use the classes in Microsoft.Phone.Net.NetworkInformation namespace to performs tasks such as determine the mobile operator, list available network connections in your phone, view and set socket connection preferences, and view and set WebRequest connection preferences. For more information, see Network and Network Interface Information for Windows Phone.
Added 12/2011
The following code samples demonstrate some of the common development tasks when you create a Windows Phone application.
SettingsSampleScreenshotDownload
C# | VB
Settings Sample
This sample shows two Settings screens, one where the settings changes take effect immediately and one where the user has to confirm the changes. For more information on adding settings to your application, see How to: Create a Settings Page for Windows Phone.
Updated 9/2011
Keyboard sample app running in the emulator.Download
C# | VB
Keyboard Index Sample
You can change the on-screen keyboard to one of 10 built-in options. This technique makes it much faster and easier for users to enter data in your applications. This sample lets you see all 10 options, and explains the highlights of each. For more information, see On-Screen Keyboard Input Scope Index for Windows Phone.
New 9/2011
GlobalizationScreenshoDownload
C# | VB
Globalization Sample
This sample shows how to use the CultureInfo class to create a Globalized application. The user selects a Locale. The application then displays information such as date, time, and currency in the correct format for the selected locale. This sample has been updated to show localization of the Application Bar and the application title that appears in the phone’s application list. For more information on globalizing and localizing your application see Globalization and Localization for Windows Phone.
Updated 9/2011
XNA Trial Application Sample ScreenshotDownload
C# | VB
XNA Framework Trial Sample
This sample demonstrates how to create a trial experience for an XNA Framework application for Windows Phone. It uses the Guide.IsTrialMode and Guide.SimulateTrialMode properties to detect the current license for the application and restrict the number of levels that the user can play as a result. Gameplay consists of trying to tap a moving square on the screen, the user progressing to the next level once they have managed to tap the moving object five times. For more information, see How to: Implement a Trial Experience in an XNA Framework Application for Windows Phone.
Updated 9/2011
Silverlight Trial Application Sample ScreenshotDownload
C# | VB
Silverlight Trial Sample
This sample demonstrates how to create a trial experience for a Silverlight application for Windows Phone. It uses the LicenseInformation class to check the current license status of the application. It walks you through example trial experiences that limit features, levels, time, and number of rounds to play. For more information, see How to: Implement a Trial Experience in a Silverlight Application for Windows Phone.
Updated 9/2011
Test ad snippetDownload
C# | VB
Ad Control Sample
Now that the Microsoft Advertising SDK is fully integrated into the Windows Phone SDK, it is easier than ever to include advertising in your applications. This sample shows you how to use the ad control to create ads on different page types, by using either XAML or code. This sample uses the built-in test ads; when you are ready to display real ads, sign up on pubCenter. For more information, see Advertising in Windows Phone Applications.
New 9/2011
Model View ViewModel Sample ScreenshotDownload
C# | VB
Model-View-ViewModel Sample
The Model-View-ViewModel (MVVM) design pattern is a great way to separate the data from the user interface in your application. This sample demonstrates a simple MVVM application that uses XAML binding to connect the Views to the Model. The application in this sample is a “game tracker” in which the user can keep track of their achievements in a video game. This sample also uses a custom data converter, maintains page state when navigating to and from the application, and saves application data to isolated storage. For more information, see Implementing the Model-View-ViewModel Pattern in a Windows Phone Application.
New 9/2011
The following code samples demonstrate the key features and functionality that you can add to your Windows Phone applications.
App Bar sample iconDownload
C# | VB
Application Bar Sample
This sample enables you to test the different Application Bar properties, such as Opacity and Mode as well as different Application Bar colors. As you click the user interface, changes are made to the Application Bar dynamically, so that you can see how the different properties work and how they interact with each other. This sample contains application bar code for a plain page, a pivot page, and a panorama page. For more information, see Walkthrough: Creating an Application Bar Test Application for Windows Phone.
Updated 9/2011
Contact names with photosDownload
C# | VB
Contacts and Calendar Sample
This sample demonstrates how to access contacts and appointments, and display the details by using data-binding. It also demonstrates two different techniques for displaying contact photos. For more information, see Contacts and Calendar for Windows Phone.
Updated 9/2011
Device Status sample screenshotDownload
C# | VB
Device Status Sample
This sample demonstrates how to use the DeviceStatus class, including accessing the properties of the class, determining if the power source of the device has changed, and determining if a physical keyboard has been deployed. For more information, see How to: Use the DeviceStatus Class for Windows Phone.
Updated 9/2011
Search Extensibility SampleDownload
C# | VB
Search Extensibility Sample
With Windows Phone OS 7.1, applications can use App Connect to extend the Search experience on Windows Phone. With App Connect, users that search the web with the Search button can launch your application from Bing search results. This sample is a fictitious product recall application for baby, nursery, and toy products. Launch this application from the apps pivot page of a quick card after searching for products like “baby doll stroller” and “baby bottle”. For more information, see Search Extensibility Overview for Windows Phone.
Updated 12/2011
AP_Con_QuickCardSampleDownload
C# | VB
Quick Card Sample
Take a convenient look at what App Connect sends your application when you extend the Search experience. This sample application displays the App Connect URI parameters when launched from the various quick cards: product cards, place cards, and movie cards. Learn more about the types of values that are associated with various search terms, and how to access those values from your application. For step-by-step information about how to develop an application like this, see How to: Extend Search with App Connect for Windows Phone.
New 12/2011
AP_Con_RSSReaderSampleDownload
C# | VB
RSS Reader Sample
This sample shows you how to create a basic RSS reader that downloads an RSS feed and displays the feed items in a ListBox. For more information, see How to: Create a Basic RSS Reader for Windows Phone.
New 9/2011
The following code samples demonstrate how to perform tasks in the background, even when the foreground application is not running.
Reminder SampleDownload
C# | VB
Scheduled Notification Sample
This sample shows you how to use the Scheduled Action Service to schedule and manage Reminders. Reminders are dialogs that pop up and display a message to the user at a time scheduled by the application that created them. For more information, see How to: Create Alarms and Reminders for Windows Phone.
Updated 9/2011
Background Transfer SampleDownload
C# | VB
Background Transfer Service Sample
This sample shows you how to use the Background Transfer Service to schedule and manage background file transfers. For more information, see How to: Implement Background File Transfers for Windows Phone.
Updated 12/2011
Background Agent SampleDownload
C# | VB
Background Agent Sample
This sample creates and registers a Periodic and a Resource-intensive background agent. These agents are able to execute code in the background, even when the application that created them is not running in the foreground. For more information, see Background Agents Overview for Windows Phone.
Updated 1/2012
The following code samples demonstrate how to use the Windows Phone camera and work with photos programmatically.
PhotosSampleScreenshotDownload
C# | VB
Photos Sample
Learn how to use a Chooser to capture a photo in your Windows Phone application. This sample uses the CameraCaptureTask to capture a photo with the built-in camera application. It also demonstrates how to crop the photo, encode it in the JPEG format, and save it to the device’s media library. For more information about working with Photos, see Camera and Photos Overview for Windows Phone.
Updated 9/2011
Basic Camera SampleDownload
C# | VB
Basic Camera Sample
Learn the basics for using the device camera in your own application. This sample demonstrates how to activate the shutter and auto focus, configure picture resolution and flash settings, and use the hardware shutter button. This sample also demonstrates touch focus and a front-facing camera for the devices that support those features. You can develop this application step-by-step by following along with a series of topics, starting with How to: Create a Base Camera Application for Windows Phone.
Updated 9/2011
Camera Greyscale SampleDownload
C# | VB
Camera Grayscale Sample
Learn how to alter live video frames in your own application. This sample demonstrates how to take Alpha, Red, Green, and Blue (ARGB) frames from the camera, convert them to grayscale, and then display them on the screen – as the camera is rolling. For step-by-step information about how to develop this application, see How to: Work with Grayscale in a Camera Application for Windows Phone.
Updated 9/2011
Camera Color Picker sample screenshotDownload
C# | VB
Camera Color Picker Sample
Explore the basics of camera color conversion with this color picker sample. This sample obtains the YCbCr components from the camera preview buffer and converts them to alpha, red, green, and blue (ARGB) for a variety of purposes. Discover how the YCbCr components relate to what you put behind the camera crosshairs. For more information about ARGB and the efficient YCbCr format, see Camera Color Conversion (YCbCr to ARGB) for Windows Phone.
Updated 9/2011
Video Recorder sample screenshotDownload
C# | VB
Video Recorder Sample
Learn how to use the device camera to record video in your own application. This sample demonstrates video preview, recording, and playback. It uses the FileSink class to write video to isolated storage, from which it can be played afterward. For detailed information about how this sample works, see How to: Record Video in a Camera Application for Windows Phone.
Updated 1/2012
The following code samples demonstrate how to work with Windows Phone controls.
PanoramaPivotSampleScreenshotDownload
C# | VB
Panorama/Pivot Sample
Unlike standard applications that are designed to fit within the confines of the phone screen, panoramic applications offer a unique way to view controls, data, and services by using a long horizontal canvas that extends beyond the confines of the screen. Alternatively, a pivot application provides a quick way to manage views or pages. The Panorama and Pivot Control sample demonstrates how to create both panoramic and pivot experiences for Windows Phone. For more information, see Pivot Control for Windows Phone and Panorama Control for Windows Phone.
Updated 9/2011
MapsSampleScreenshotDownload
C# | VB
Bing Maps Sample
The Map Sample demonstrates how to use the basic functionality of the Bing Maps Silverlight Control for Windows Phone. For more information on using the Bing Maps Silverlight Control, see Bing Maps Silverlight Control for Windows Phone.
Updated 9/2011
TIltEffectScreenshotDownload
C# | VB
Tilt Effect Sample
The tilt effect for Windows Phone controls provides you with the ability to add additional visual feedback for control interaction. It provides a “tilt” like response when the control is touched. The Control Tilt Effect sample demonstrates how to implement the tilt effect in an application. For more information on adding a tilt effect to the controls in your application, see Control Tilt Effect for Windows Phone.
Updated 9/2011
Custom Indeterminate Progress Bar SampleDownload
C# | VB
Custom Indeterminate Progress Bar Sample
This sample shows you how to create a custom indeterminate progress bar that runs on the compositor thread for better performance. For more information about this sample, see How to: Create a Custom Indeterminate Progress Bar.
Updated 9/2011
The following code samples demonstrate location-aware applications and how to determine the orientation and motion of a Windows Phone device.
Raw Sensor Data SampleDownload
C# | VB
Raw Sensor Data Sample
This sample shows you how to obtain data from the Compass, Accelerometer, and Gyroscope sensors. For more information, see Sensors Overview for Windows Phone.
Updated 1/2012
Simple Motion SampleDownload
C# | VB
Simple Motion Sample
The Motion API uses multiple device sensors to calculate the position and motion of the device. This example uses the Yaw component of the device’s attitude to rotate a triangle. For more information, see How to: Use the Combined Motion API for Windows Phone.
Updated 9/2011
Augmented Reality Motion SampleDownload
C# | VB
Augmented Reality Motion Sample
This sample uses the Motion API and the PhotoCamera class to create an Augmented Reality application that lets you pin labels to points in space as you rotate the device. For more information, see How to: Use the Combined Motion API for Windows Phone.
Updated 9/2011
Shake Gesture Library SampleDownload
C# | VB
Shake Gesture Library Sample
This sample uses the Shake Gesture Library provided by the Windows Phone team to test shake data that was prerecorded in Windows Phone Emulator. For more information about using the simulated accelerometer data provided by Windows Phone Emulator, see How to: Test Applications that Use the Accelerometer.
Updated 9/2011
Location Service Sample ScreenshotDownload
C# | VB
Location Service Sample
This is a simple application that receives data from the Microsoft Location Service and displays the geographic coordinates of the device. For more information on the Microsoft Location Service, see Location for Windows Phone.
Updated 9/2011
The following code samples demonstrate how to interact with the robust media platform that Windows Phone provides.
MusicAndVideosHubSampleScreenshotDownload
C# | VB
Music + Videos Hub Sample
This sample shows how to use the MediaHistory and MediaHistoryItem classes to create a Music + Videos Hub application. It also uses the XNA MediaPlayer class to control playback of music. When the user presses the Play button, a history item is added to the Music + Videos Hub. You can then use this history item to launch the application and play that song immediately. If you start application while a song is already playing in the media player, the application displays information about the currently playing song. For more information on integrating your application into the Music + Videos Hub, please see How to: Integrate with the Music and Videos Hub for Windows Phone.
Updated 9/2011
SIlverlight Sound Sample ScreenshotDownload
C# | VB
Sound Sample
This sample demonstrates how to use the XNA Framework's SoundEffect class and the Silverlight MediaElement class to play multiple sounds simultaneously in a Silverlight application for Windows Phone. It also shows a simple way to setup a GameTimer to call FrameworkDispatcher.Update in order to simulate the Game loop for the XNA Framework's internals. It shows how to load a wave audio file into a Stream that can be played by the SoundEffect classes. Finally, it demonstrates how to pause and resume the playback of the Zune media player as required by the Application Certification Requirements for Windows Phone.
Updated 9/2011
Silverlight Microphone Sample ScreenshotDownload
C# | VB
Microphone Sample
This sample demonstrates how to get audio input from the microphone in a Silverlight for Windows Phone application by using the Microsoft.Xna.Framework.Audio.Microphone class. It also shows how to play audio using the SoundEffect and SoundEffectInstance classes. The code monitors audio playback on a separate thread and updates the user interface when the sound stops playing. For more information on accessing the microphone in a Silverlight application, please see How to: Access the Microphone in a Silverlight Application for Windows Phone
Updated 9/2011
Ringtones SampleDownload
C# | VB
Custom Ringtones Sample
This sample implements a simple application that allows the user to save a custom ringtone to the Windows Phone ringtone library where it can be selected as the system ringtone or assigned to a specific contact. It includes code to preview the ringtone and simulates an architecture that would enable downloading ringtones from a remote location. Also see How to: Use the Save Ringtone Task for Windows Phone.
Updated 9/2011
Background Audio Player SampleDownload
C# | VB
Background Audio Player Sample
This sample implements an AudioPlayerAgent that allows audio to play even when the application is not in the foreground. This background agent will run under the lock screen where the user can control the audio using the universal volume control (UVC). Also see How to: Play Background Audio for Windows Phone.
Updated 9/2011
Background Audio Streamer sample screenshotDownload
C# | VB
Background Audio Streamer Sample
The Background Audio Streamer sample demonstrates how to create an app that uses a MediaStreamSource to stream audio content from an AudioStreamingAgent. This agent will run in the background and under the lock screen where you can control the audio using the Universal Volume Control (UVC). You can also control audio playback directly from the user interface of the application, when it is the foreground app. The sample uses a simple sine wave generator to simulate an audio stream, so it does not depend on a network connection. For more information about background audio, see Background Audio Overview for Windows Phone.
Updated 9/2011
The following code samples demonstrate how to manage the flow of information between users, applications, online sites, services, and Start Tiles.
Tile SampleDownload
C# | VB
Tile Sample
Demonstrates how to create, update, and delete secondary Tiles. The Tile updates demonstrate how to update the properties on both the front and back of a Tile. The update techniques can also be applied to Application Tiles. For more information, see Tiles Overview for Windows Phone.
Updated 9/2011
Shell Tile Schedule SampleDownload
C# | VB
Shell Tile Schedule Sample
Demonstrates how to update the background image on the front of the Tile on a regular schedule. Background images on the front of a secondary Tile can be updated in the same way. For more information, see Tiles Overview for Windows Phone.
Updated 9/2011
Tile Notification SampleDownload
C# | VB
Tile Notification Sample
Demonstrates how to update a Tile using the Microsoft Push Notification Service. This sample contains two projects – one project for the client code that sets up the Windows Phone device to receive a notification and another project that sends the notification to the Microsoft Push Notification Service. For more information, see Push Notifications for Windows Phone.
Updated 9/2011
Toast Notification SampleDownload
C# | VB
Toast Notification Sample
Demonstrates how to send a toast notification to a Windows Phone using the Microsoft Push Notification Service. This sample contains two projects – one project for the client code that sets up the Windows Phone device to receive a notification and another project that sends the notification to the Microsoft Push Notification Service. For more information, see Push Notifications for Windows Phone.
Updated 9/2011
Raw Notification SampleDownload
C# | VB
Raw Notification Sample
Demonstrates how to send data to a Windows Phone using a raw notification. This sample contains two projects – one project for the client code that sets up the Windows Phone device to receive a notification and another project that sends the notification to the Microsoft Push Notification Service. For more information, see Push Notifications for Windows Phone.
Updated 9/2011
For XNA-specific code samples, see the XNA content catalog.
These articles introduce the basics for creating Windows Phone applications, from “Hello World” to phone sensors. They include samples, code snippets, and videos all presented in a prescribed order like the chapters of a book.
To view the Quick Starts, see Windows Phone Development Quick Starts.
The Windows Phone Training Kit for Windows Phone 7.5 release includes scenario based hands-on-labs that demonstrate individual usage of individual features plus the integration of all these features coming together to accomplish a real-world task. The training kit’s “To-do” application demonstrates local database, multi-tasking, reminders, and fast application switching support coming together to implement a semi-functional task management application.
To view the training kit, see Windows Phone Training Kit.

Using a Local Database in a “To-do” Application

This hands-on-lab will show you how to use SQL Compact Edition (SQL CE) to build a task management (“To-do”) application. You will first learn how to apply the right attributes to an existing object model so that the DataContext class can create a relational database with keys and constraints. You will also learn how to query the database using LINQ-to-SQL.

Using the Background Transfer Service in a “To-do” Application

This hands-on-lab will show you how to use BackgroundTransferService to transfer (upload and download) data between your Windows Phone Application and the internet. Using the new multi-tasking capabilities in Windows Phone 7.5, BackgroundTransferService can transfer files even when your application is not running. This lab will show you how to schedule transfers, query their progress, and manage your download queue. The transfers are doing back-up and restore of the SQL CE database in the “To-do” scenario-based sample.

Fast Application Switching in a “To-do” application

Fast Application Switching (FAS) allows for applications to stay dormant (in-memory) after deactivation to get a very responsive time when the user navigates back to the application. By detecting whether your application is being activated from dormant state instead of a tombstoned state you can optimize your application to have immediate resume times. This lab will show you how to use the ActivatedEventArgs parameter in the application life-cycle events to the test if our “To-do” application instance was preserved using FAS.

Creating Reminders in the “To-do” application

Scheduling notifications that trigger even when your application is not in the foreground is a critical multi-tasking task for some apps, like alarm clocks, calendaring, and birthday apps. This lab uses the new ScheduledActionService to create and manage reminders to a “To-do” application. The application will also show you how deep linking works when the user clicks on a reminder and that launches your application to an actionable page with context from the reminder.
Back to Top

Technical Article – Developing a Windows Phone Application from Start to Finish

This documentation and accompanying sample application will get you started building a complete application that targets Windows Phone OS 7.1. You will learn the basics of Windows Phone development by creating a simple fuel-tracking application for your car.
To view the article, see Developing a Windows Phone Application from Start to Finish.
Back to Top

Technical Article – A Case Study for Building Advanced Windows Phone Applications

This article walks through the scenario of creating an advanced Windows Phone application that is a client of an existing cloud-based application.
To view the article, see A Case Study for Building Advanced Windows Phone Applications.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น