【发布时间】:2015-09-21 20:59:44
【问题描述】:
在 Android 中我们有广播,在 iOS 中我们有 NSNotifiactionCenter 来发送后台消息和通知...
Windows Phone 8.1 中有类似的东西?? 我正在寻找有关此的文档,但我找不到任何东西。
非常感谢!! 豪尔赫。
【问题讨论】:
标签: notifications windows-phone-8.1
在 Android 中我们有广播,在 iOS 中我们有 NSNotifiactionCenter 来发送后台消息和通知...
Windows Phone 8.1 中有类似的东西?? 我正在寻找有关此的文档,但我找不到任何东西。
非常感谢!! 豪尔赫。
【问题讨论】:
标签: notifications windows-phone-8.1
WP 8.1 中没有广播,但为此我正在使用 Caliburn 框架的实现。
https://github.com/Caliburn-Micro/Caliburn.Micro/blob/master/src/Caliburn.Micro/EventAggregator.cs
编辑:
或者您可以实现自己的广播 - 我在我的一个项目中使用了它
using System;
using System.Collections.Generic;
/* Created by Jan Kobersky - 8/28/2015 6:46:06 PM */
namespace EveryDay.Code.Core
{
public class EventDispatcher
{
private static EventDispatcher _data;
public static EventDispatcher Dispatcher => _data ?? (_data = new EventDispatcher());
private readonly List<object> _subscribers = new List<object>();
private EventDispatcher()
{
}
public void Subscribe(object subscriber)
{
if (!_subscribers.Contains(subscriber))
{
_subscribers.Add(subscriber);
}
}
public void Unsubscribe(object subscriber)
{
if (_subscribers.Contains(subscriber))
{
_subscribers.Remove(subscriber);
}
}
public void Dispatch<T>(T message) where T : class
{
foreach (var subscriber in _subscribers)
{
(subscriber as IHandle<T>)?.Handle(message);
}
}
}
public interface IHandle<T> where T : class
{
void Handle(T message);
}
}
【讨论】: