Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------
- ' Ejemplo de toast notifications (18/Ene/13)
- '
- ' El artículo en mi blog:
- ' http://www.elguillemola.com/index.php/2013/01/ejemplo-sencillo-de-notificaciones-toast-para-windows-store/
- '
- ' ©Guillermo 'guille' Som, 2013
- '------------------------------------------------------------------------------
- Option Strict On
- Option Infer On
- Imports Windows.UI.Notifications
- Imports Windows.Data.Xml.Dom
- ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
- ''' <summary>
- ''' An empty page that can be used on its own or navigated to within a Frame.
- ''' </summary>
- Public NotInheritable Class MainPage
- Inherits Page
- ''' <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 Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
- End Sub
- Private Sub ButtonPlay_Click(sender As Object, e As RoutedEventArgs)
- ' La plantilla a usar, esta Text03 es:
- ' un texto de cabecera que puede ocupar dos líneas y una línea de texto normal
- Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText03
- ' Asignamos el template a un documento Xml
- Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
- ' El texto para el primero elemento de la pantilla
- Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
- toastTextElements(0).AppendChild(toastXml.CreateTextNode("Cargando ..."))
- ' Si queremos que la duración sea larga
- ' Puede ser corta o larga, corta es la predeterminada
- Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
- TryCast(toastNode, XmlElement).SetAttribute("duration", "long")
- ' Si queremos quitar el sonido
- ' (o indicar alguno en particular)
- ' tenemos que usar el elemento "audio"
- 'Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
- Dim audio As XmlElement = toastXml.CreateElement("audio")
- audio.SetAttribute("silent", "true")
- toastNode.AppendChild(audio)
- Dim toast As New ToastNotification(toastXml)
- ToastNotificationManager.CreateToastNotifier().Show(toast)
- End Sub
- Private Sub ButtonClock_Click(sender As Object, e As RoutedEventArgs)
- ' La plantilla a usar, esta Text03 es:
- ' un texto de cabecera que puede ocupar dos líneas y una línea de texto normal
- Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText03
- ' Asignamos el template a un documento Xml
- Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
- ' El texto para el primero elemento de la pantilla
- Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
- toastTextElements(0).AppendChild(
- toastXml.CreateTextNode("A los 3 segundos después de haber pulsado en el botón."))
- toastTextElements(1).AppendChild(
- toastXml.CreateTextNode("Segundo texto."))
- ' Esto es para indicar que esta notificación se hará en el momento indicado
- Dim dueTime As DateTime = DateTime.Now.AddSeconds(3)
- Dim scheduledToast As New ScheduledToastNotification(toastXml, dueTime)
- ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast)
- End Sub
- Private Sub ButtonHelp_Click(sender As Object, e As RoutedEventArgs)
- ' La plantilla a usar, esta Text02 es:
- ' un texto de cabecera y un texto normal que puede ocupar dos líneas
- Dim toastTemplate As ToastTemplateType = ToastTemplateType.ToastText02
- ' Asignamos el template a un documento Xml
- Dim toastXml As XmlDocument = ToastNotificationManager.GetTemplateContent(toastTemplate)
- ' El texto para el primero elemento de la pantilla
- Dim toastTextElements As XmlNodeList = toastXml.GetElementsByTagName("text")
- toastTextElements(0).AppendChild(
- toastXml.CreateTextNode("Esto se mostrará durante más tiempo ..."))
- toastTextElements(1).AppendChild(
- toastXml.CreateTextNode("Siempre puedes cerrar las notificaciones en la X superior."))
- ' Si queremos que la duración sea larga
- ' Puede ser corta o larga, corta es la predeterminada
- Dim toastNode As IXmlNode = toastXml.SelectSingleNode("/toast")
- TryCast(toastNode, XmlElement).SetAttribute("duration", "long")
- ' Esto es para indicar que esta notificación se hará en el momento indicado
- Dim dueTime As DateTime = DateTime.Now.AddSeconds(10)
- Dim scheduledToast As New ScheduledToastNotification(toastXml, dueTime)
- ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast)
- Dim toast As New ToastNotification(toastXml)
- ToastNotificationManager.CreateToastNotifier().Show(toast)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement