forked from microsoft/Windows-universal-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowConnection.xaml.cs
99 lines (87 loc) · 3.21 KB
/
ShowConnection.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
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;
using Windows.Networking.NetworkOperators;
using System.Collections.Generic;
namespace MobileBroadband
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ShowConnection : Page
{
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
// as NotifyUser()
MainPage rootPage = MainPage.Current;
private IReadOnlyList<string> deviceAccountId = null;
public ShowConnection()
{
this.InitializeComponent();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
PrepareScenario();
}
/// <summary>
/// This is the click handler for the 'Default' button. You would replace this with your own handler
/// if you have a button or buttons on this page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ShowConnectionUI_Click(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
if (b != null)
{
try
{
var mobileBroadbandAccount = MobileBroadbandAccount.CreateFromNetworkAccountId(deviceAccountId[0]);
mobileBroadbandAccount.CurrentNetwork.ShowConnectionUI();
}
catch (Exception ex)
{
rootPage.NotifyUser("Error:" + ex.Message, NotifyType.ErrorMessage);
}
}
}
void PrepareScenario()
{
rootPage.NotifyUser("", NotifyType.StatusMessage);
try
{
deviceAccountId = MobileBroadbandAccount.AvailableNetworkAccountIds;
if (deviceAccountId.Count != 0)
{
ShowConnectionUI.Content = "Show Connection UI";
ShowConnectionUI.IsEnabled = true;
}
else
{
ShowConnectionUI.Content = "No available accounts detected";
ShowConnectionUI.IsEnabled = false;
}
}
catch (Exception ex)
{
rootPage.NotifyUser("Error:" + ex.Message, NotifyType.ErrorMessage);
}
}
}
}