Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a Toastnotification in a WPF app

I created a WpfApplication in C# (with Visual Studio Community 2015) and i'd like to send some windows 10 notifications. I think that I'm supposed to use "ToastContent" then add it into a "ToastNotification",...

I've add "Microsoft.Toolkit.Uwp.Notification" but I can't add "Microsoft.Toolkit.Uwp.UI" (that I think is needed to display the notification). It says :

Could not install package 'Microsoft.Toolkit.Uwp 1.2.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework.

What can I do to install this package ? Or is there another solution to launch a windows 10 notification ?

Thank you :)

like image 643
MBek Avatar asked Dec 28 '16 11:12

MBek


1 Answers

Ok, after a few hours of searching, this is kind of easy...

Step 1 : Unload the projet then add to the first property group this element : <targetplatformversion>10.0</targetplatformversion>

Step 2 : Reload the projet

Step 3 : Add references to your project "Windows > Core > Windows.Data & Windows.UI"

Step 4 :

string xml = $@"
            <toast>
                <visual>
                    <binding template='ToastGeneric'>
                        <text>Some title</text>
                        <text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text>
                    </binding>
                </visual>
            </toast>";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);

        var toast = new ToastNotification(doc);

        ToastNotificationManager.CreateToastNotifier("ToastDesktop").Show(toast);

Enjoy :) !

like image 91
MBek Avatar answered Oct 07 '22 02:10

MBek