About six weeks ago I developed a C# console app as a proof of concept to generate a Windows 10 toast notification. Worked fine. I revisit the solution only to find it builds and runs without errors, but the toast notification no longer displays. Have researched thoroughly on SO and so far no love. Hoping someone in the community can point me in the right direction, so here goes:
Environment
- Windows 10, version 1709
- .NET framework 4.6.1
- Visual Studio 2017, version 15.7.4
.csproj file addition
<PropertyGroup>
<TargetPlatformVersion>10.0.1709</TargetPlatformVersion>
</PropertyGroup>
Added References
- Windows.Data
- Windows.UI
- System.Runtime (from .NETFramework\v4.6.1\Facades)
Program.cs
using System;
using System.IO;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
class Program
{
private const String APP_ID = "CompanyName.Notifier.ToastName";
static void Main(string[] args)
{
ToastContent content = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Desired text",
HintMaxLines = 1
},
new AdaptiveText()
{
Text = "More desired text"
},
},
HeroImage = new ToastGenericHeroImage()
{
Source = @"C:\Logo.png" // hard-coded path for testing
}
}
},
Duration = ToastDuration.Long
};
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(content.GetContent());
var tstVisual = new ToastNotification(xmlDoc);
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(tstVisual);
}
}
Additional Thoughts
I checked the XML generation (did a File.WriteAllText
with the XML obtained with content.GetContent()
) and the toast XML generates fine. It seems like something is preventing the ToastNotificationManager.CreateToastNotifier
from displaying the toast notification. Thanks for looking at this.