5

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 :)

MBek
  • 155
  • 10
  • are you creating Universal Windows App or just regular WPF app? – Paweł Łukasik Dec 28 '16 at 11:19
  • It is a regular WPF app : File > New > Project > Templates/Visual C#/Windows/Classic Desktop > WPF Application. – MBek Dec 28 '16 at 11:23
  • then I think you can't use Universal Windows' reference (Microsoft.Toolkit.Uwp) in such project. – Paweł Łukasik Dec 28 '16 at 11:25
  • I think it's somehow possible and that's why i'm supposed to use Microsoft.Toolkit.UI instead of Windows.UI – MBek Dec 28 '16 at 11:28
  • Possible duplicate of [WPF Desktop App, Windows 10 Notification Toast 2016 (UWP Community Toolkit)](http://stackoverflow.com/questions/39744331/wpf-desktop-app-windows-10-notification-toast-2016-uwp-community-toolkit) – Paweł Łukasik Dec 28 '16 at 11:37
  • http://stackoverflow.com/questions/39744331/wpf-desktop-app-windows-10-notification-toast-2016-uwp-community-toolkit#39895774 – Paweł Łukasik Dec 28 '16 at 11:37

1 Answers1

4

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 :) !

MBek
  • 155
  • 10