2016-08-14 9 views
1

나는 아무 말도하지 않고 로컬 스토리지에 데이터를 보관하는 간단한 UWP 쇼핑 목록 앱이 있습니다. 앱이 일시 중지되면 현재 목록을 로컬 저장소에 씁니다. 이 (또는 OnNavigatedFrom 메인 페이지)에서 내가하고 싶은 일은 라이브 타일을 업데이트하여 사용자가 앱을 시작하지 않고도이 사실을 볼 수 있도록 현재 목록에있는 항목 수를 표시하는 것입니다 .간단한 UWP 라이브 타일 업데이트

다음과 같은 간단한 경우를 처리하는 문서/샘플을 찾는 데 문제가 있습니다 ... 백그라운드 작업이없고 푸시 알림도없고 일정에 따라 아무런 변화가 없으며 본질적으로 타일에 대한 간단한 업데이트가 필요합니다. 사용자 행동. 내가 찾을 수있는 예제는 TileUpdater을 사용하는 것으로 보입니다.하지만이 간단한 경우에 사용해야하는지, 또는 사용해야하는지에 대해서는 이해하지 못합니다.

업데이트 할 코드에서 수행해야 할 최소한의 단계는 무엇입니까? 배지 카운트 (거기에 값을 넣고 카운트가 0 일 때 제거)는 무엇입니까?

답변

2

내 대답을 찾았습니다.

using Windows.Data.Xml.Dom; 
using Windows.UI.Notifications; 

    /// <summary> 
    /// Add a badge count to the application tile (or remove if the count is zero) 
    /// </summary> 
    /// <param name="count">Number of items</param> 
    public static void Update(int count) 
    { 
     // Get an XmlDocument containing the badge template 
     var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); 

     // Get the "badge" element 
     var badgeElement = (XmlElement)badgeXml.GetElementsByTagName("badge").First(); 

     // Set the count in its "value" attribute (as string) 
     badgeElement.SetAttribute("value", count.ToString()); 

     // Create a badge notification from the XML content. 
     var badgeNotification = new BadgeNotification(badgeXml); 

     // Send the badge notification to the app's tile. 
     BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification); 
    } 
+0

이 방식은 나를 위해 일한 :

내가 내가 내가 배지 카운트를 업데이트해야 할 때마다 호출 다음과 같은 방법으로 추가되는 서비스 클래스를 만들었습니다. 배지를 제거하려면 0을 전달하십시오. – Del