2011-09-18 3 views
13

में मेट्रो टाइल अधिसूचनाएं मैं टाइल अधिसूचनाओं के साथ सी # में एक साधारण विंडोज 8 मेट्रो स्टाइल ऐप को एक साथ रखने की कोशिश कर रहा हूं लेकिन मुझे उन्हें काम नहीं मिल रहा है।सी #

जो मैं अभी तक समझ नहीं पा रहा हूं वह है जहां टाइल अधिसूचनाओं को अद्यतन करने के लिए कोड होना चाहिए। मैंने Javascript sample पर एक नज़र डाली है, लेकिन मुझे नहीं लगता कि यह सी # ऐप में कैसे काम करता है। क्या किसी को कुछ नमूना कोड या त्वरित टिप मिली है जहां सी # मेट्रो ऐप में टाइल अपडेट होना चाहिए?

उत्तर

15

मेरी समझ यह है कि प्रत्येक ऐप यह तय करता है कि यह अपने लिए कहां करें। आम तौर पर, जब भी आप एक ही डेटा के साथ अपना सामान्य यूआई अपडेट कर रहे हों तो आप ऐसा करेंगे - उदा। यदि आपका ऐप एक आरएसएस रीडर है, और आपने अभी प्रदर्शित करने के लिए एक नया आइटम डाउनलोड किया है, तो वह जगह है जहां आप अधिसूचना पोस्ट करके अपनी टाइल अपडेट भी करते हैं। नमूना जावास्क्रिप्ट ऐप में, यह सुविधा के लिए नियंत्रण के लिए ईवेंट हैंडलर से किया जाता है।

टाइल बदलने के लिए कोड के रूप में, यह जावास्क्रिप्ट संस्करण के लगभग समान होना चाहिए, क्योंकि दोनों मामलों में आप Windows.UI.Notifications namespace का उपयोग करते हैं। निम्नलिखित एक बहुत ही सरल सी # ऐप है जो बटन पर क्लिक करते समय टाइल अपडेट करता है। XAML:

<UserControl x:Class="TileNotificationCS.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    d:DesignHeight="768" d:DesignWidth="1366"> 
    <StackPanel x:Name="LayoutRoot" Background="#FF0C0C0C"> 
     <TextBox x:Name="message"/> 
     <Button x:Name="changeTile" Content="Change Tile" Click="changeTile_Click" /> 
    </StackPanel> 
</UserControl> 

और कोड के पीछे:

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

namespace TileNotificationCS 
{ 
    partial class MainPage 
    { 
     TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); 

     public MainPage() 
     { 
      InitializeComponent(); 
     } 

     private void changeTile_Click(object sender, RoutedEventArgs e) 
     { 
      XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText01); 
      XmlElement textElement = (XmlElement)tileXml.GetElementsByTagName("text")[0]; 
      textElement.AppendChild(tileXml.CreateTextNode(message.Text)); 
      tileUpdater.Update(new TileNotification(tileXml)); 
     } 
    } 
} 

भूल जाते हैं कि आप एक विस्तृत टाइल की जरूरत पाठ दिखाने के लिए नहीं है - हो यह, "वाइड लोगो" के लिए कुछ छवि पैकेज में स्थापित करने के लिए .appxmanifest।

+0

आह है! मेरा टाइल अभी भी एक वर्ग था। इसे व्यापक रूप से बदल दिया और यह काम किया। –

1

सुनिश्चित करें कि आप लैंडस्केप में प्रारंभिक रोटेशन बदलते हैं, Widelogo के लिए कुछ छवि सेट करें, और इस विधि का उपयोग समाप्ति के साथ पाठ को सेट करने के लिए करें।

void SendTileTextNotification(string text, int secondsExpire) 
     { 
      // Get a filled in version of the template by using getTemplateContent 
      var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText03); 

      // You will need to look at the template documentation to know how many text fields a particular template has  

      // get the text attributes for this template and fill them in 
      var tileAttributes = tileXml.GetElementsByTagName(&quot;text&quot;); 
      tileAttributes[0].AppendChild(tileXml.CreateTextNode(text)); 

      // create the notification from the XML 
      var tileNotification = new TileNotification(tileXml); 

      // send the notification to the app's default tile 
      TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); 
     } 

यहाँ एक विस्तृत विवरण http://www.amazedsaint.com/2011/09/hellotiles-simple-c-xaml-application.html