Toast通知在右上角有一个“关闭按钮”。我想在用户点击UWP应用程序中的“关闭按钮”时记录时间戳。是否可以实现
答案 0 :(得分:0)
您可以使用秒表。
只要你愿意就开始,并在被解雇的事件上花费时间:
private Stopwatch _timer = new Stopwatch();
private void ShowToastNotification()
{
_timer.Start();
//show your toast here
}
private void OnDismissed(ToastNotification sender, ToastDismissedEventArgs args)
{
var time = _timer.Elapsed;
//do anything with your time here
}
答案 1 :(得分:0)
ToastNotificationHistoryChangedTrigger。
public class MyBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
var details = taskInstance.TriggerDetails as ToastNotificationHistoryChangedTriggerDetail;
if (details != null)
{
if (details.ChangeType == ToastHistoryChangedType.Cleared || details.ChangeType == ToastHistoryChangedType.Removed)
{
// your code - get current time
}
}
deferral.Complete();
}
}