Windows Phone 8.1 Tiles, Notifications and Action Center

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   java   

(1)Tiles

Tiles 也就是磁貼,是 Windows Phone 的一大特色。

一個 Tile 其實可以看成是一個 XML,比如:

<tile>  <visual>    <binding template="TileSquareImage">      <image id="1" src="image1" alt="alt text"/>    </binding>    </visual></tile><tile>  <visual version="2">    <binding template="TileSquare150x150Image" fallback="TileSquareImage">      <image id="1" src="image1" alt="alt text"/>    </binding>    </visual></tile>

微軟為我們提供了一系列模板,具體可參照:連結

只要根據模板的 XML 格式,便可輕鬆的更新 Tile:

private void updateButton_Click(object sender, RoutedEventArgs e){    UpdateTiles("ms-appx:///Images/Middle.png", "ms-appx:///Images/Wide.png");}private void UpdateTiles(string middlePath, string widePath){    string tileString = "<tile>" +                           "<visual version=\"2\">" +                              "<binding template=\"TileSquare150x150PeekImageAndText04\" fallback=\"TileSquarePeekImageAndText04\">" +                                  "<image id=\"1\" src=\"" + middlePath + "\" alt=\"alt text\"/>" +                                  "<text id=\"1\"></text>" +                                "</binding>" +                                "<binding template=\"TileWide310x150ImageAndText01\" fallback=\"TileWideImageAndText01\">" +                                  "<image id=\"1\" src=\"" + widePath + "\" alt=\"alt text\"/>" +                                  "<text id=\"1\"></text>" +                              "</binding>" +                           "</visual>" +                       "</tile>";    XmlDocument tileXML = new XmlDocument();    tileXML.LoadXml(tileString);    TileNotification newTile = new TileNotification(tileXML);    TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();    updater.EnableNotificationQueue(false);    updater.Update(newTile);}

除了主磁貼外我們還可以建立 SecondaryTile:

private void createButton_Click(object sender, RoutedEventArgs e){    CreateTile("ms-appx:///Images/Middle.png", "ms-appx:///Images/Wide.png");}private async void CreateTile(string middlePath, string widePath){    SecondaryTile tile = new SecondaryTile("Cortana", "Cortana", "Some", new Uri(middlePath), TileSize.Default);    tile.VisualElements.ShowNameOnSquare150x150Logo = true;    tile.VisualElements.ForegroundText = ForegroundText.Dark;    tile.VisualElements.Square30x30Logo = new Uri(middlePath);    tile.VisualElements.Wide310x150Logo = new Uri(widePath);    await tile.RequestCreateAsync();}

SecondaryTile 的更新與主磁貼更新一樣:

TileUpdater update = TileUpdateManager.CreateTileUpdaterForSecondaryTile("Cortana");

 

(2)Notifications

Notification(推播通知)分為 Tile,Badge,Toast,Raw 四種類型,而通知的方式又分為 Scheduled,Periodic,Local,Push 四種,它們之間對應的關係為:

使用方法都大同小異,根據各自的 XML 格式修改再調用 Update 方法即可,例如:

XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);ToastNotification toast = new ToastNotification(xml);ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();notifier.Show(toast);

需要注意的是:(1)Toast 通知需要在 Manifest 中許可;(2)Push 方法為:

private async void SendRawNotification(){    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();    channel.PushNotificationReceived += channel_PushNotificationReceived;}private void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args){    var raw = args.RawNotification;}

 

(3)Action Center

1)每個應用最多可以在 Action Center 中駐留 20 條通知

2)通知最多可駐留 7 天

3)可發送靜默通知(不會提示使用者)

toast1.SuppressPopup = true;

4)可對通知進行分組

XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);ToastNotification toast1 = new ToastNotification(xml);toast1.Group = "One";toast1.Tag = "1";

5)可更新或刪除通知(可刪除某一組)

ToastNotificationManager.History.RemoveGroup("One");

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.