IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Toast notification C# winapp UWP


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Août 2023
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Août 2023
    Messages : 3
    Par défaut Toast notification C# winapp UWP
    Bonjour, je suis en train d apprendre le C# via visual studio et je suis en train de créer une application qu irais afficher une notification toast sur W10. Je suis parvenu à créer mon toast notification avec ce code

    " // template to load for showing Toast Notification
    var xmlToastTemplate = "<toast launch=\"app-defined-string\">" +
    "<visual>" +
    "<binding template =\"ToastGeneric\">" +
    "<text>Sample Notification</text>" +
    "<text>" +
    "This is a sample toast notification from kunal-chowdhury.com" +
    "</text>" +
    "</binding>" +
    "</visual>" +
    "</toast>";

    // load the template as XML document
    var xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(xmlToastTemplate);

    // create the toast notification and show to user
    var toastNotification = new ToastNotification(xmlDocument);
    var notification = ToastNotificationManager.CreateToastNotifier();
    notification.Show(toastNotification); ""

    Dans ce code on script la partie xml ça fonctionne mais moi j aimerait charger un fichier toast xml déjà existant sur mon poste par exemple dans C:\toast.xml.

    Je ne parvient pas à trouver la ligne permettant de faire un load xml extérieur à mon projet C#. Pouvez vous m'aider ?

  2. #2
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 251
    Par défaut
    tu remplace xmlDocument.LoadXml(xmlToastTemplate); par xmlDocument.Load(@"C:\toast.xml");

  3. #3
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Août 2023
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Août 2023
    Messages : 3
    Par défaut
    Bonjour merci pour votre répondre,

    Je viens de faire le test :


    Citation Envoyé par sevyc64 Voir le message
    tu remplace xmlDocument.LoadXml(xmlToastTemplate); par xmlDocument.Load(@"C:\toast.xml");
    mais maintenant j'ai une partie de mon script n'est pas reconnu le XmlDocument "var xmlDocument = new XmlDocument"



    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.Data.Xml.Dom;
    using Microsoft.Toolkit.Uwp.Notifications;
    using Windows.UI.Notifications;
    using System.Xml.Linq;
    using System.Linq;
    using System.Reflection;
    using System.Xml;
    // Pour plus d'informations sur le modèle d'élément Page vierge, consultez la page https://go.microsoft.com/fwlink/?Lin...52&clcid=0x409

    namespace App4
    {
    /// <summary>
    /// Une page vide peut être utilisée seule ou constituer une page de destination au sein d'un frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
    public MainPage()
    {
    this.InitializeComponent();
    // Construct the content and schedule the toast!
    // template to load for showing Toast Notification



    // template to load for showing Toast Notification

    // template to load for showing Toast Notification

    // load the template as XML document
    var xmlDocument = new XmlDocument();
    xmlDocument.Load("@C:\toast.xml");

    // create the toast notification and show to user
    var toastNotification = new ToastNotification(xmlDocument);
    var notification = ToastNotificationManager.CreateToastNotifier();
    notification.Show(toastNotification);



    // create the toast notification and show to user

    // Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater
    // Not seeing the Show() method? Make sure you have version 7.0, and if you're using .NET 6 (or later), then your TFM must be net6.0-windows10.0.17763.0 or greater }
    }
    }
    }

  4. #4
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 251
    Par défaut
    vérifie ton fichier xml, il est sans doute pas valide.
    Déjà les chaines de caractères dans un xml, normalement c'est avec des apostrophes, pas des guillemets.

  5. #5
    Candidat au Club
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Août 2023
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Août 2023
    Messages : 3
    Par défaut
    Citation Envoyé par sevyc64 Voir le message
    vérifie ton fichier xml, il est sans doute pas valide.
    Déjà les chaines de caractères dans un xml, normalement c'est avec des apostrophes, pas des guillemets.
    Bonjour, merci pour votre reponse, ce fichier xml fonctionne car je réalise la même chose mais avec powershell qui fonctionne sans problème

    auriez vous un exemple de toast notification qui fonctionne chez vous à partir d'un fichier ?

    pouvez vous reproduire le test et me montrer le script qui fonctionne chez vous ?

  6. #6
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 251
    Par défaut
    Bon, ça semble beaucoup plus compliqué en UWP, je n'en avais jamais fait, je découvre.

    Le problème vient de la classe XmlDocument. Celle à utiliser avec Toast vient du namespace Windows.Data.Xml.Dom, pas du namespace habituel System.Xml.
    Les 2 classes ne sont pas identiques et il ne semble pas y avoir de passerelle entre les 2.

    Il faut donc utiliser directement la bonne classe, mais avec celle-ci, ce n'est pas simple de charger un fichier qui vient du disque local (dû aussi à la particularité de UWP, droits d'accès, etc ...)

    J'ai réussi à faire quelque chose. Par contre ton fichier xml devra être dans le dossier d'installation de ton application avec cet exemple :
    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
                // create the toast notification and show to user
                StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                StorageFile xmlFile = await storageFolder.GetFileAsync("toast.xml"); 
                var buffer = await FileIO.ReadBufferAsync(xmlFile);
     
                var x = new Windows.Data.Xml.Dom.XmlDocument();
                x.LoadXmlFromBuffer(buffer);
     
                var toastNotification = new ToastNotification(x);
                var notification = ToastNotificationManager.CreateToastNotifier();
                notification.Show(toastNotification);

Discussions similaires

  1. Calendrier et Toast Notification Windows 8 app Store
    Par kadilldév dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 02/02/2014, 10h06
  2. [SNMP] différences entre traps et notifications?
    Par fadoua dans le forum Développement
    Réponses: 2
    Dernier message: 06/07/2004, 11h57
  3. Réponses: 5
    Dernier message: 08/01/2004, 15h05
  4. Réponses: 3
    Dernier message: 01/07/2003, 16h04
  5. [CODE] Application dans la zone de notification
    Par Rodrigue dans le forum C++Builder
    Réponses: 4
    Dernier message: 29/05/2003, 19h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo