sale phone lanzamiento historia cuando características caracteristicas silverlight windows-phone-8 windows-phone-8.1 dispatcher

silverlight - historia - windows phone 10 lanzamiento



Obteniendo la página actual al recibir una notificación de brindis(WP8.1 Silverlight, recibiendo notificación de brindis WNS) (2)

De acuerdo. Prueba esto. Crea una propiedad estática en App.xaml.cs.

public static object CurrentPageInfo { get; set; }

Y asigne el tipo de página o el nombre de la página a la propiedad en el método ''OnNavigatedTo'' en cada página.

protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var currentPage = ((PhoneApplicationFrame)Application.Current.RootVisual).Content; App.CurrentPageInfo = currentPage.GetType() is BC_Menu.StartUp.SecondScreen; }

Para que pueda identificar el tipo de fuente de la página al recibir notificaciones accediendo a la propiedad App.CurrentPageInfo . ¡Espero eso ayude!

Tengo un evento que se activa cuando la aplicación está activa y recibo una notificación CurrentChannel_PushNotificationReceived . En esta función, quiero saber qué página se muestra actualmente para saber si la notificación debe actualizar el contenido de la página. La pregunta es por lo tanto doble, cómo saber qué página se muestra actualmente e interactuar con la notificación de brindis.

Actualización El problema es que no puedo interactuar con los elementos debido al choque con el enrutamiento del sistema operativo (Dispatcher).

Por lo tanto, utilizando el siguiente código me permite acceder al contenido del mensaje. Pero aún no puedo obtener la información de la página actual

_channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); _channel.PushNotificationReceived += OnPushNotificationReceived;

private void OnPushNotificationReceived (PushNotificationChannel sender, PushNotificationReceivedEventArgs args) {switch (args.NotificationType) {case PushNotificationType.Badge: this.OnBadgeNotificationReceived (args.BadgeNotification.Content.GetXml ()); descanso;

case PushNotificationType.Tile: this.OnTileNotificationReceived(args.TileNotification.Content.GetXml()); break; case PushNotificationType.Toast: this.OnToastNotificationReceived(args.ToastNotification.Content.GetXml()); break; case PushNotificationType.Raw: this.OnRawNotificationReceived(args.RawNotification.Content); break; } args.Cancel = true; } private void OnBadgeNotificationReceived(string notificationContent) { // Code when a badge notification is received when app is running } private void OnTileNotificationReceived(string notificationContent) { // Code when a tile notification is received when app is running } private void OnToastNotificationReceived(string notificationContent) { // Code when a toast notification is received when app is running // Show a toast notification programatically var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(notificationContent); var toastNotification = new ToastNotification(xmlDocument); //toastNotification.SuppressPopup = true; ToastNotificationManager.CreateToastNotifier().Show(toastNotification); } private void OnRawNotificationReceived(string notificationContent) { // Code when a raw notification is received when app is running }

Pregunta

¿Cómo onXXXXNotificationReceived información de la página actual en los diferentes onXXXXNotificationReceived ? Los fragmentos actuales funcionan pero no dentro de estas funciones:

var currentPage = ((PhoneApplicationFrame)Application.Current.RootVisual).Content; var tempBool = currentPage.GetType() is BC_Menu.StartUp.SecondScreen;

o

RootFrame.CurrentSource;

Supongo que es por el hilo de UI. Entonces, ¿cómo puedo usar el despachador para obtener la información? He intentado algunas soluciones con el despachador, pero no puedo esperar la información y, por lo tanto, no es aplicable.

System.Windows.Threading.DispatcherOperation op = App.RootFrame.Dispatcher.BeginInvoke(new Func<Uri>(() => { return RootFrame.CurrentSource; }) ); await op; //Not awaitable.


No hay ninguna razón para esperar al despachador al hilo de UI. Simplemente envíe al hilo de la interfaz de usuario y luego realice el resto de su lógica, como mostrar las tostadas o navegar por una página, desde el hilo de la interfaz de usuario ...

Registra el evento ...

var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); channel.PushNotificationReceived += Channel_PushNotificationReceived;

En el controlador de eventos, cancele la visualización de la notificación y luego envíela al hilo de la interfaz de usuario ...

private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { // Make sure you cancel displaying the toast on this thread (not on UI thread) // since cancellation needs to be set before this thread/method returns args.Cancel = true; // Then dispatch to the UI thread App.RootFrame.Dispatcher.BeginInvoke(delegate { var currPage = ((PhoneApplicationFrame)Application.Current.RootVisual).Content; switch (args.NotificationType) { case PushNotificationType.Toast: // TODO break; } }); }

Haga todo su código dentro del delegado del despachador. Todo su código se ejecutará en el hilo de la interfaz de usuario ... podrá navegar por las páginas, obtener la página actual, etc.