This repository was archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToasts.cs
More file actions
40 lines (33 loc) · 1.27 KB
/
Toasts.cs
File metadata and controls
40 lines (33 loc) · 1.27 KB
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
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Notification;
namespace Cloudsdale {
public static class Toasts {
public static readonly string ChannelName = "CDNotifications";
public static event EventHandler<NotificationChannelErrorEventArgs> ErrorOccurred;
public static void GetToastUri(Action<Uri> callback) {
var channel = HttpNotificationChannel.Find(ChannelName);
if (channel == null) {
channel = new HttpNotificationChannel(ChannelName);
channel.RegisterEvents(callback);
channel.Open();
channel.BindToShellToast();
} else {
channel.RegisterEvents(callback);
}
callback(channel.ChannelUri);
}
private static void RegisterEvents(this HttpNotificationChannel channel, Action<Uri> changedCallback) {
channel.ChannelUriUpdated += (sender, args) => changedCallback(args.ChannelUri);
channel.ErrorOccurred += ErrorOccurred;
}
}
}