Wpf toast message 활용하기
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
public void ShowCustomizedToastNotification(string title, string message, string imageFilePath, string audioFilePath, int durationInSeconds)
{
// Set up the XML content for the toast notification
var xml = $@"
<toast activationType='foreground' launch='toastParam'>
<visual>
<binding template='ToastGeneric'>
<image src='{imageFilePath}' placement='appLogoOverride' hint-crop='circle'/>
<text hint-style='title'>{title}</text>
<text hint-style='body'>{message}</text>
<text hint-style='base' hint-align='center' hint-wrap='true'>This is a long message that should wrap to multiple lines in the notification.</text>
</binding>
</visual>
<audio src='{audioFilePath}' loop='true'/>
<actions>
<action activationType='background' arguments='snooze' content='Snooze'/>
<action activationType='background' arguments='dismiss' content='Dismiss'/>
</actions>
<inputs>
<input id='comment' type='text' placeHolderContent='Add a comment (optional)'/>
</inputs>
<toastArguments>param1=value1&param2=value2</toastArguments>
<toastScenario>reminder</toastScenario>
<duration>{durationInSeconds}</duration>
<visualLang><lang xml:lang='en-US'/></visualLang>
<audioLang><lang xml:lang='en-US'/></audioLang>
<launch>app-defined-string</launch>
<group>group1</group>
<tag>notificationTag</tag>
<suppressPopup>false</suppressPopup>
<hint-systemPriority>2</hint-systemPriority>
<hint-userInputNeeded>true</hint-userInputNeeded>
</toast>";
// Create a new XML document from the XML content
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
// Create a new toast notification from the XML document
var toastNotification = new ToastNotification(xmlDoc);
// Set the expiration time for the notification
var expirationTime = DateTimeOffset.UtcNow.AddSeconds(durationInSeconds);
toastNotification.ExpirationTime = expirationTime;
// Set up the toast notifier and show the notification
var toastNotifier = ToastNotificationManager.CreateToastNotifier("AppUserModelID");
toastNotifier.Show(toastNotification);
}
This code creates a new ShowCustomizedToastNotification method that accepts five parameters: title, message, imageFilePath, audioFilePath, and durationInSeconds. The method creates a new XML document with many of the available properties, including:
Visual content with an image, title, message, and a long message that wraps to multiple lines
An audio element that plays an audio file and loops it
Two actions that are shown with the notification
An input field that allows the user to enter a comment
Several additional properties, including toastArguments, toastScenario, duration, visualLang, audioLang, launch, group, tag, suppressPopup, hint-systemPriority, and hint-userInputNeeded
To use this method in your WPF application, you can call it from any event handler or method, passing in the appropriate title, message, imageFilePath, audioFilePath, and durationInSeconds parameters. Note that some of the properties, such as group and tag, are used to group or identify multiple