-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
138 lines (119 loc) · 5.22 KB
/
MainPage.xaml.cs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WalletDemo.Resources;
using Windows.System;
using Microsoft.Phone.Wallet;
using System.Windows.Media.Imaging;
using Microsoft.Phone.Tasks;
namespace WalletDemo
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
// 用于本地化 ApplicationBar 的示例代码
//BuildLocalizedApplicationBar();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
WalletItemCollection wc = await Wallet.GetItemsAsync();
foreach (var item in wc)
{
if (item.Id == "deal1")
{
dealbutton.IsEnabled = false;
}
if (item.Id == "walletTransactionItem1")
{
transationbutton.IsEnabled = false;
}
if (item.Id == "paymentInstrument1")
{
bank.IsEnabled = false;
}
}
base.OnNavigatedTo(e);
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("wallet://", UriKind.RelativeOrAbsolute));
}
private async void Button_Click_2(object sender, RoutedEventArgs e)
{
Deal deal = new Deal("deal1");
deal.MerchantName = "某某公司";
deal.DisplayName = "某某优惠卡";
deal.IsUsed = false;
await deal.SaveAsync();
MessageBox.Show("添加优惠券信息成功");
}
private async void Button_Click_3(object sender, RoutedEventArgs e)
{
string msg = "";
WalletItemCollection wc = await Wallet.GetItemsAsync();
foreach (var item in wc)
{
msg += item.DisplayName+"|";
}
MessageBox.Show(msg);
}
private void transationbutton_Click(object sender, RoutedEventArgs e)
{
WalletTransactionItem walletTransactionItem = new WalletTransactionItem("walletTransactionItem1");
walletTransactionItem.DisplayName = "会员卡";
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(Application.GetResourceStream(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)).Stream);
walletTransactionItem.Logo159x159 = bitmapImage;
walletTransactionItem.Logo336x336 = bitmapImage;
walletTransactionItem.Logo99x99 = bitmapImage;
AddWalletItemTask addWalletItemTask = new AddWalletItemTask();
addWalletItemTask.Item = walletTransactionItem;
addWalletItemTask.Completed += addWalletItemTask_Completed;
addWalletItemTask.Show();
}
void addWalletItemTask_Completed(object sender, AddWalletItemResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show("添加成功");
}
}
private void bank_Click(object sender, RoutedEventArgs e)
{
PaymentInstrument paymentInstrument = new PaymentInstrument("paymentInstrument1");
paymentInstrument.DisplayName = "我的银行卡";
paymentInstrument.PaymentInstrumentKinds = PaymentInstrumentKinds.Credit;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(Application.GetResourceStream(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)).Stream);
paymentInstrument.Logo159x159 = bitmapImage;
paymentInstrument.Logo336x336 = bitmapImage;
paymentInstrument.Logo99x99 = bitmapImage;
AddWalletItemTask addWalletItemTask = new AddWalletItemTask();
addWalletItemTask.Item = paymentInstrument;
addWalletItemTask.Completed += addWalletItemTask_Completed;
addWalletItemTask.Show();
}
// 用于生成本地化 ApplicationBar 的示例代码
//private void BuildLocalizedApplicationBar()
//{
// // 将页面的 ApplicationBar 设置为 ApplicationBar 的新实例。
// ApplicationBar = new ApplicationBar();
// // 创建新按钮并将文本值设置为 AppResources 中的本地化字符串。
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);
// // 使用 AppResources 中的本地化字符串创建新菜单项。
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}