How to use the add Wallet item task for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Use the add Wallet item task to launch the Wallet application and allow the user to add the supplied item to his or her Wallet. If the user completes the task, an event is raised and the event handler receives an TaskResult value indicating whether the item was successfully added to the Wallet. This is the only way for apps to add a PaymentInstrument or a WalletTransactionItem. To add a Deal, use the SaveAsync()()() method. For more information on creating applications that use Wallet, see Wallet for Windows Phone 8.
By using Choosers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.
To use the add Wallet item task
Add the following statement to your code.
Imports Microsoft.Phone.Tasks
using Microsoft.Phone.Tasks;
Imports Microsoft.Phone.Wallet Imports System.Windows.Media.Imaging
using Microsoft.Phone.Wallet; using System.Windows.Media.Imaging;
Declare the task object. It must have page scope, so declare it in your page before the constructor.
Dim addWalletItemTask As AddWalletItemTask = New AddWalletItemTask()
AddWalletItemTask addWalletItemTask = new AddWalletItemTask();
Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.
AddHandler addWalletItemTask.Completed, AddressOf addWalletItemTask_Completed
addWalletItemTask.Completed += addWalletItemTask_Completed;
Instantiate one of the supported objects that inherit from WalletItem and set the Item property of the AddWalletItemTask object. Only PaymentInstrument and WalletTransactionItem objects are supported for this chooser. The following properties must be set before calling AddWalletItemTask..::.Show or an InvalidOperationException will be thrown.
Wallet Item Type |
Required Fields |
---|---|
DisplayName, PaymentInstrumentKinds, Logo99x99, Logo159x159, Logo336x336 |
|
Add the code for the completed event handler to your page. This code runs after the user completes the task. The result is an AddWalletItemResult object that contains the name and address of the contact.
void addWalletItemTask_Completed(object sender, AddWalletItemResult e) { if (e.TaskResult == TaskResult.OK) { MessageBox.Show(e.Item.Id + " was added to your Wallet"); } }