记录用户单击Toast通知中的关闭按钮的时间

时间:2016-12-22 07:38:29

标签: windows-store-apps uwp win-universal-app

Toast通知在右上角有一个“关闭按钮”。我想在用户点击UWP应用程序中的“关闭按钮”时记录时间戳。是否可以实现

2 个答案:

答案 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)

带有Register background task触发器的

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();
    }
}