2016-02-16 2 views
6

Utilizzo di .NET WPF e Windows 10, c'è un modo per inviare una notifica di notifica locale sul centro operativo utilizzando C#? Ho visto solo persone che creano finestre di dialogo personalizzate per questo, ma ci deve essere un modo per farlo attraverso il sistema operativo.Windows nativo WPF 10 toast

+0

Io in realtà uso quella biblioteca, ora non mi resta che scoprire dove i metodi sono;/ – shady

+0

@AbinMathew Metro.Mahapps non ha nulla a che fare con brindisi nativi. –

+0

@shady Per quanto mi ricordi, l'unico modo per mostrare i toasts delle app Win32 è usare COM. –

risposta

2

È possibile utilizzare un NotifyIcon da System.Windows.Forms namespace in questo modo:

class Test 
{ 
    private readonly NotifyIcon _notifyIcon; 

    public Test() 
    { 
     _notifyIcon = new NotifyIcon(); 
     // Extracts your app's icon and uses it as notify icon 
     _notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); 
     // Hides the icon when the notification is closed 
     _notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false; 
    } 

    public void ShowNotification() 
    { 
     _notifyIcon.Visible = true; 
     // Shows a notification with specified message and title 
     _notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info); 
    } 

} 

Questo dovrebbe funzionare dal .NET Framework 1.1. Fare riferimento a this MSDN page per i parametri di ShowBalloonTip.

Come ho scoperto, il primo parametro di ShowBalloonTip (nel mio esempio che sarebbe 3000 millisecondi) viene generosamente ignorato. I commenti sono apprezzati;)

2

UPDATE

Questo sembra funzionare bene su Windows 10

https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx

dovrai aggiungere questi nugets

Install-Package WindowsAPICodePack-Core 
Install-Package WindowsAPICodePack-Shell 
+0

Non è possibile eseguire questa operazione in WPF. – Perfection

+1

@Perfection penso che questo dovrebbe andare bene per l'OP cosa ne pensi? –

+0

Questo sembra interessante. Potrei andare a prenderlo da solo. Sono riuscito a risolverlo la scorsa notte facendo riferimento a Windows.winmd da un Resource Kit. – Perfection

0

sono riuscito per accedere all'API di lavoro per Windows 8 e 10 facendo riferimento a

  • Windows.winmd: C: \ Program Files (x86) \ Windows Kits \ 8.0 \ Riferimenti \ CommonConfiguration \ Neutral

Ciò espone Windows.UI.Notifications.

+0

Non ho quella DLL in quella directory: / – shady