Advertisement
elGuille

Código de VB del ejemplo de toast notifications

Jan 17th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.22 KB | None | 0 0
  1. '------------------------------------------------------------------------------
  2. ' Ejemplo de toast notifications                                    (18/Ene/13)
  3. '
  4. ' El artículo en mi blog:
  5. ' http://www.elguillemola.com/index.php/2013/01/ejemplo-sencillo-de-notificaciones-toast-para-windows-store/
  6. '
  7. ' ©Guillermo 'guille' Som, 2013
  8. '------------------------------------------------------------------------------
  9. Option Strict On
  10. Option Infer On
  11.  
  12. Imports Windows.UI.Notifications
  13. Imports Windows.Data.Xml.Dom
  14.  
  15. ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  16.  
  17. ''' <summary>
  18. ''' An empty page that can be used on its own or navigated to within a Frame.
  19. ''' </summary>
  20. Public NotInheritable Class MainPage
  21.     Inherits Page
  22.  
  23.     ''' <summary>
  24.     ''' Invoked when this page is about to be displayed in a Frame.
  25.     ''' </summary>
  26.     ''' <param name="e">Event data that describes how this page was reached.  The Parameter
  27.     ''' property is typically used to configure the page.</param>
  28.     Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
  29.  
  30.     End Sub
  31.  
  32.     Private Sub ButtonPlay_Click(sender As Object, e As RoutedEventArgs)
  33.  
  34.         ' La plantilla a usar, esta Text03 es:
  35.         ' un texto de cabecera que puede ocupar dos líneas y una línea de texto normal
  36.         Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText03
  37.         ' Asignamos el template a un documento Xml
  38.         Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
  39.  
  40.         ' El texto para el primero elemento de la pantilla
  41.         Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
  42.         toastTextElements(0).AppendChild(toastXml.CreateTextNode("Cargando ..."))
  43.  
  44.         ' Si queremos que la duración sea larga
  45.         ' Puede ser corta o larga, corta es la predeterminada
  46.         Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
  47.         TryCast(toastNode, XmlElement).SetAttribute("duration", "long")
  48.  
  49.         ' Si queremos quitar el sonido
  50.         ' (o indicar alguno en particular)
  51.         ' tenemos que usar el elemento "audio"
  52.         'Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
  53.         Dim audio As XmlElement = toastXml.CreateElement("audio")
  54.         audio.SetAttribute("silent", "true")
  55.         toastNode.AppendChild(audio)
  56.  
  57.  
  58.         Dim toast As New ToastNotification(toastXml)
  59.         ToastNotificationManager.CreateToastNotifier().Show(toast)
  60.     End Sub
  61.  
  62.     Private Sub ButtonClock_Click(sender As Object, e As RoutedEventArgs)
  63.  
  64.         ' La plantilla a usar, esta Text03 es:
  65.         ' un texto de cabecera que puede ocupar dos líneas y una línea de texto normal
  66.         Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText03
  67.         ' Asignamos el template a un documento Xml
  68.         Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
  69.  
  70.         ' El texto para el primero elemento de la pantilla
  71.         Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
  72.         toastTextElements(0).AppendChild(
  73.             toastXml.CreateTextNode("A los 3 segundos después de haber pulsado en el botón."))
  74.         toastTextElements(1).AppendChild(
  75.             toastXml.CreateTextNode("Segundo texto."))
  76.  
  77.         ' Esto es para indicar que esta notificación se hará en el momento indicado
  78.         Dim dueTime As DateTime = DateTime.Now.AddSeconds(3)
  79.         Dim scheduledToast As New ScheduledToastNotification(toastXml, dueTime)
  80.  
  81.         ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast)
  82.  
  83.     End Sub
  84.  
  85.     Private Sub ButtonHelp_Click(sender As Object, e As RoutedEventArgs)
  86.         ' La plantilla a usar, esta Text02 es:
  87.         ' un texto de cabecera y un texto normal que puede ocupar dos líneas
  88.         Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText02
  89.         ' Asignamos el template a un documento Xml
  90.         Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
  91.  
  92.         ' El texto para el primero elemento de la pantilla
  93.         Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
  94.         toastTextElements(0).AppendChild(
  95.             toastXml.CreateTextNode("Esto se mostrará durante más tiempo ..."))
  96.         toastTextElements(1).AppendChild(
  97.             toastXml.CreateTextNode("Siempre puedes cerrar las notificaciones en la X superior."))
  98.  
  99.         ' Si queremos que la duración sea larga
  100.         ' Puede ser corta o larga, corta es la predeterminada
  101.         Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
  102.         TryCast(toastNode, XmlElement).SetAttribute("duration", "long")
  103.  
  104.         ' Esto es para indicar que esta notificación se hará en el momento indicado
  105.         Dim dueTime As DateTime = DateTime.Now.AddSeconds(10)
  106.         Dim scheduledToast As New ScheduledToastNotification(toastXml, dueTime)
  107.  
  108.         ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast)
  109.  
  110.         Dim toast As New ToastNotification(toastXml)
  111.         ToastNotificationManager.CreateToastNotifier().Show(toast)
  112.  
  113.     End Sub
  114. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement