I am trying to implement Toast Notification from Console App in C# using the below code.
I also tried the wpf code, and it works just fine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications; // Notifications library
using Windows.Data.Xml.Dom;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
// In a real app, these would be initialized with actual data
string title = "Andrew sent you a picture";
string content = "Check this out, Happy Canyon in Utah!";
string image = "http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-71-81-permanent/2727.happycanyon1_5B00_1_5D00_.jpg";
string logo = "ms-appdata:///local/Andrew.jpg";
int conversationId = 384928;
// Construct the visuals of the toast
ToastVisual visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
new AdaptiveImage()
{
Source = image
}
},
AppLogoOverride = new ToastGenericAppLogo()
{
Source = logo,
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
};
// Construct the actions for the toast (inputs and buttons)
ToastActionsCustom actions = new ToastActionsCustom()
{
Inputs =
{
new ToastTextBox("tbReply")
{
PlaceholderContent = "Type a response"
}
}
};
// Now we can construct the final toast content
ToastContent toastContent = new ToastContent()
{
Visual = visual,
Actions = actions,
// Arguments when the user taps body of toast
};
//Console.WriteLine(toastContent.GetContent());
//Console.ReadKey();
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(toastContent.GetContent());
// And create the toast notification
ToastNotification notification = new ToastNotification(xDoc);
// And then send the toast
ToastNotificationManager.CreateToastNotifier("Test").Show(notification);
}
}
}
I dont see any errrors in the code, but for some reason the Toast is not showing up.
The same code works perfectly with WPF app.
Can anyone help me what i am missing here?