Windows 10에서는 전경 또는 배경에서 토스트 알림 활성화를 처리 할 수 있습니다. Windows 10에서는 <action>
요소에 activationType
특성을 갖는 적응 형 및 대화 형 알림을 소개합니다. 이 속성을 사용하면이 작업이 어떤 종류의 활성화를 유발할 지 지정할 수 있습니다. 예를 들어 다음과 토스트를 사용하면 : 사용자가 "자세한 내용을 참조하십시오"버튼을 클릭하면
<toast launch="app-defined-string">
<visual>
<binding template="ToastGeneric">
<text>Microsoft Company Store</text>
<text>New Halo game is back in stock!</text>
</binding>
</visual>
<actions>
<action activationType="foreground" content="See more details" arguments="details"/>
<action activationType="background" content="Remind me later" arguments="later"/>
</actions>
</toast>

, 그것은 전경에 응용 프로그램을 가져올 것이다. Application.OnActivated method은 새 activation kind - ToastNotification으로 호출됩니다. 그리고 우리는 다음과 같이이 활성화를 처리 할 수
protected override void OnActivated(IActivatedEventArgs e)
{
// Get the root frame
Frame rootFrame = Window.Current.Content as Frame;
// TODO: Initialize root frame just like in OnLaunched
// Handle toast activation
if (e is ToastNotificationActivatedEventArgs)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
// Get the argument
string args = toastActivationArgs.Argument;
// TODO: Handle activation according to argument
}
// TODO: Handle other types of activation
// Ensure the current window is active
Window.Current.Activate();
}
사용자가 클릭
버튼을 "나중에 알림", 그것은 전경 응용 프로그램을 활성화하는 대신 백그라운드 작업을 트리거합니다. 따라서 백그라운드 작업에서 다른 백그라운드 작업을 시작할 필요가 없습니다.
토스트 알림에서 백그라운드 활성화를 처리하려면 백그라운드 작업을 만들고 등록해야합니다. 백그라운드 작업은 앱 매니페스트에서 "시스템 이벤트" 작업으로 선언하고 트리거를 ToastNotificationActionTrigger으로 설정해야합니다. 그런 다음 백그라운드 작업에 같은 클릭되는 버튼을 결정하기 위해 미리 정의 된 인수를 검색 할 수 ToastNotificationActionTriggerDetail를 사용
public sealed class NotificationActionBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
if (details != null)
{
string arguments = details.Argument;
// Perform tasks
}
}
}
이 더 많은 정보
Adaptive and interactive toast notifications, 특히
Handling activation (foreground and background)를 참조하십시오. GitHub에
the complete sample도 있습니다.
유용한 것으로 보입니다. http://www.kunal-chowdhury.com/2016/02/uwp-tips-toast-button.html –