自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows 8開發(fā)之動(dòng)態(tài)磁貼和輔助磁貼

開發(fā) 后端
磁貼在系統(tǒng)的開始菜單中代表著應(yīng)用,動(dòng)態(tài)磁貼可以向用戶顯示新的、重大的、定制的內(nèi)容。 Tile 通知是一種固定格式的 XML,其中包含文字和圖片內(nèi)容。

在應(yīng)用程序清單中,必須包含一張正方形的的 logo,如果 應(yīng)用程序也想使用寬模版 logo,也需要在清單中注明。如果你的應(yīng)用中同樣支持寬 tile,強(qiáng)烈建議你預(yù)加載 方形和寬形 在預(yù)加 載的 xml 中,從而無論開始菜單中的 tile 是方形或者 寬形的 都可以接收通知。

以下是微軟提供的磁貼模版:

磁貼和磁貼通知 : http://msdn.microsoft.com/zh-cn/library/windows/apps/hh779724.aspx

磁貼模板目錄 :    http://msdn.microsoft.com/zh-cn/library/windows/apps/hh761491.aspx

1.動(dòng)態(tài)磁貼

  使用 Windows.UI.Notifications 命名空間下的 TileUpdateManager 類, 創(chuàng)建用于更改和更新啟動(dòng)菜單圖塊的 TileUpdater對(duì)象。此類提供對(duì)系統(tǒng)提供的平鋪模板 XML 內(nèi)容的訪問,以便您可以自定義用于更新您平鋪的內(nèi)容。 具體模版的XML內(nèi)容,可以根據(jù)微軟的模版,進(jìn)行修改。

  1. public static class TileUpdateManager 
  2.    { 
  3.        // 摘要: 
  4.        //     創(chuàng)建并初始化 TileUpdater 的新實(shí)例,此操作可讓您更改調(diào)用應(yīng)用程序圖塊的外觀。 
  5.        // 
  6.        // 返回結(jié)果: 
  7.        //     用于將更改發(fā)送到應(yīng)用程序的平鋪的對(duì)象。 
  8.        [Overload("CreateTileUpdaterForApplication")] 
  9.        public static TileUpdater CreateTileUpdaterForApplication(); 
  10.        // 
  11.        // 摘要: 
  12.        //     創(chuàng)建并初始化圖塊 TileUpdater 的新實(shí)例,該圖塊屬于和調(diào)用應(yīng)用程序位于同一包中的另一應(yīng)用程序。TileUpdater 允許開發(fā)人員更改該平鋪外觀。 
  13.        // 
  14.        // 參數(shù): 
  15.        //   applicationId: 
  16.        //     標(biāo)題的唯一 ID。 
  17.        // 
  18.        // 返回結(jié)果: 
  19.        //     用于通過 applicationId 將更改發(fā)送到平鋪標(biāo)識(shí)的對(duì)象。 
  20.        [Overload("CreateTileUpdaterForApplicationWithId")] 
  21.        public static TileUpdater CreateTileUpdaterForApplication(string applicationId); 
  22.        // 
  23.        // 摘要: 
  24.        //     創(chuàng)建并初始化 TileUpdater 的新實(shí)例,此操作可讓您更改 secondary tile 的外觀。平鋪可屬于調(diào)用應(yīng)用程序或相同包中的其他任何應(yīng)用程序。 
  25.        // 
  26.        // 參數(shù): 
  27.        //   tileId: 
  28.        //     標(biāo)題的唯一 ID。 
  29.        // 
  30.        // 返回結(jié)果: 
  31.        //     用于通過 tileID 將更新發(fā)送到平鋪標(biāo)識(shí)的對(duì)象。 
  32.        public static TileUpdater CreateTileUpdaterForSecondaryTile(string tileId); 
  33.       // 
  34.        // 摘要: 
  35.        //     獲取預(yù)定義的圖塊模板之一的 XML 內(nèi)容,這樣您可以自定義該內(nèi)容以進(jìn)行圖塊更新。 
  36.        // 
  37.        // 參數(shù): 
  38.        //   type: 
  39.        //     模板的名稱。 
  40.        // 
  41.        // 返回結(jié)果: 
  42.        //     包含 XML 的對(duì)象。 
  43.        public static XmlDocument GetTemplateContent(TileTemplateType type); 
  44.    } 
  45.        //使用模版自定義字的符串 
  46.        void UpdateTileButton_Click(object sender, RoutedEventArgs e) 
  47.        { 
  48.            string tileXmlString = "<tile>" 
  49.                              + "<visual>" 
  50.                              + "<binding template='TileWideImageAndText01'>" 
  51.                              + "<text id='1'>This tile notification uses ms-appx images</text>" 
  52.                              + "<image id='1' src='ms-appx:///images/redWide.png' alt='Red image'/>" 
  53.                              + "</binding>" 
  54.                              + "<binding template='TileSquareImage'>" 
  55.                              + "<image id='1' src='ms-appx:///images/graySquare.png' alt='Gray image'/>" 
  56.                              + "</binding>" 
  57.                              + "</visual>" 
  58.                              + "</tile>"
  59.            Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument(); 
  60.            tileDOM.LoadXml(tileXmlString); 
  61.            TileNotification tile = new TileNotification(tileDOM); 
  62.           TileUpdateManager.CreateTileUpdaterForApplication().Update(tile); 
  63.        } 

  另外我們可以下載NotificationsExtensions文件,將該文件引用到我們的項(xiàng)目中,使用該文件中提供的類和方法來創(chuàng)建我們的動(dòng)態(tài)磁貼,這個(gè)和前面不同的地方是,我們可以不使用XML模版進(jìn)行設(shè)置磁貼的模版,而是通過具體的模版類,給模版類的屬性賦值,實(shí)現(xiàn)動(dòng)態(tài)磁貼。下面的代碼實(shí)現(xiàn)了,最近五個(gè)動(dòng)態(tài)磁貼之間的切換,該模版顯示的樣式為:

寬磁貼:左側(cè)是一個(gè)較小的圖像,右側(cè)上面是第一行上較大文本的標(biāo)題字符串,下面是四行四個(gè)常規(guī)文本的字符串。文本不自動(dòng)換行。

窄磁貼:上面是一個(gè)較大文本的標(biāo)題字符串,下面是一個(gè)最多可包含三行自動(dòng)換行常規(guī)文本的字符串。

   

  1. private void UpdateTileText(string key,string[] array)  //array數(shù)組有4個(gè)元素,分別顯示四行數(shù)據(jù) 
  2.     { 
  3.         try 
  4.         { 
  5.             if (array != null && array.Length > 1) 
  6.             { 
  7.                 //創(chuàng)建方形磁帖模板,ITileSquareText02上面是一個(gè)較大文本的標(biāo)題字符串,下面是一個(gè)最多可包含三行自動(dòng)換行常規(guī)文本的字符串。      
  8.                 ITileSquareText02 squareContent = TileContentFactory.CreateTileSquareText02(); 
  9.                 squareContent.TextHeading.Text = key; 
  10.                 squareContent.TextBodyWrap.Text = array[0]; 
  11.                 //創(chuàng)建寬模板,ITileWideSmallImageAndText02左側(cè)是一個(gè)較小的圖像,右側(cè)上面是第一行上較大文本的標(biāo)題字符串,下面是四行四個(gè)常規(guī)文本的字符串。文本不自動(dòng)換行。     
  12.                 ITileWideSmallImageAndText02 tileContent = TileContentFactory.CreateTileWideSmallImageAndText02(); 
  13.                 tileContent.Image.Src = "ms-appx:///Assets/Logo.png"
  14.                 tileContent.TextHeading.Text = word; 
  15.                 for (int i = 0; i < array.Length; i++) 
  16.                 { 
  17.                     switch (i) 
  18.                     { 
  19.                         case 0: 
  20.                             tileContent.TextBody1.Text = array[i];  //第一行數(shù)據(jù) 
  21.                             break
  22.                         case 1: 
  23.                             tileContent.TextBody2.Text = array[i];  //第二行數(shù)據(jù) 
  24.                             break
  25.                         case 2: 
  26.                             tileContent.TextBody3.Text = array[i];  //第三行數(shù)據(jù) 
  27.                             break
  28.                         case 3: 
  29.                             tileContent.TextBody4.Text = array[i];  //第四行數(shù)據(jù) 
  30.                             break
  31.                     } 
  32.                 } 
  33.                 tileContent.SquareContent = squareContent; 
  34.              TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());                 
  35.  TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);                
  36.             } 
  37.         } 
  38.         catch 
  39.         { 
  40.         } 

 

注意:動(dòng)態(tài)磁貼必須要在實(shí)體機(jī)器上,在模擬器中是無法顯示動(dòng)態(tài)磁貼的效果。

  2.輔助磁貼(二級(jí)磁貼)

  輔助磁貼使用戶能夠?qū)?Windows 應(yīng)用商店應(yīng)用的特定內(nèi)容和深層鏈接—對(duì)固定應(yīng)用內(nèi)部一個(gè)特定位置的引用—發(fā)送到“開始”屏幕上。輔助磁貼使用戶能夠使用好友、新聞源、股票報(bào)價(jià)和其他對(duì)其很重要的內(nèi)容來個(gè)性化“開始”屏幕體驗(yàn)。創(chuàng)建輔助磁貼的選項(xiàng)最常在 UI 中顯示為“附到開始菜單”選項(xiàng)。固定內(nèi)容也就是為它創(chuàng)建輔助磁貼。此選項(xiàng)常常顯示為應(yīng)用欄上的一個(gè)標(biāo)志符號(hào)。通過觸摸或單擊來選擇輔助磁貼,會(huì)啟動(dòng)到父應(yīng)用,以突出一種以固定內(nèi)容或聯(lián)系人為中心的體驗(yàn)。只有用戶才可以固定輔助磁貼;應(yīng)用不能在未獲得用戶許可的情況下以編程方式固定輔助磁貼。用戶還可以通過“開始”屏幕或通過父應(yīng)用,對(duì)輔助磁貼進(jìn)行顯式刪除控制。

  1).在固定輔助磁貼前,用戶必須確認(rèn),要求對(duì)此進(jìn)行確認(rèn)的彈出窗口應(yīng)當(dāng)顯示在調(diào)用固定請(qǐng)求的按鈕旁邊。

 

  1. public Rect GetElementRect(FrameworkElement element)   
  2. {   
  3.    GeneralTransform buttonTransform = element.TransformToVisual(null);   
  4.    Point point = buttonTransform.TransformPoint(new Point());   
  5.    return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));   
  6.  }  

 

  2).添加輔助磁貼。首先需要設(shè)置輔助磁貼的ID

  1.  public const string appbarTileId = "SecondaryTile.AppBar"
  2.  private async void AddButtonClicked(object sender, RoutedEventArgs e)   
  3. {   
  4.    //當(dāng)用戶選擇應(yīng)用欄上的按鈕時(shí),會(huì)顯示一個(gè)要求用戶進(jìn)行確認(rèn)的彈出窗口。   
  5.    //若要確保在顯示彈出窗口時(shí)不取消應(yīng)用欄,必須設(shè)置應(yīng)用欄的 IsSticky 屬性。   
  6.    this.BottomAppBar.IsSticky = true;   
  7.    if(SecondaryTile.Exists(appbarTileId))   
  8.    {   
  9.      //取消相應(yīng)的輔助磁貼   
  10.       SecondaryTile secondaryTile = new SecondaryTile(appbarTileId);   
  11.       bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);   
  12.       ToggleAppBarButton(isUnpinned);   
  13.    }   
  14.     else  
  15.    {   
  16.         //輔助磁貼的一些屬性需要設(shè)置后才能固定輔助磁貼.   
  17.         //•磁貼的唯一 ID   
  18.         //•短名稱   
  19.         //•顯示名稱   
  20.         //•磁貼選項(xiàng)   
  21.         //•徽標(biāo)圖像   
  22.         //•激活輔助磁貼時(shí)將傳遞到父應(yīng)用程序的參數(shù)字符串   
  23.         Uri logo = new Uri("ms-appx:///Assets/logo.jpg");   
  24.        string tileActivationArguments = appbarTileId + " was pinned at " + DateTime.Now.ToLocalTime().ToString();   
  25.        SecondaryTile secondaryTile = new SecondaryTile(appbarTileId,   
  26.                                                         "Secondary tile pinned via AppBar",   
  27.                                                              "SDK Sample Secondary Tile pinned from AppBar",                                                         tileActivationArguments,                                                             TileOptions.ShowNameOnLogo,   
  28.                                logo);   
  29.             //指定前景文本顏色和小徽標(biāo)。   
  30.               secondaryTile.ForegroundText = ForegroundText.Dark;   
  31.               secondaryTile.SmallLogo = new Uri("ms-appx:///Assets/small.jpg");   
  32.              //調(diào)用異步方法將輔助磁貼固定。   
  33.              //實(shí)際上這種方法不是將磁貼直接固定到“開始”屏幕,而是會(huì)顯示一個(gè)要求用戶允許這樣做的確認(rèn)提示框。   
  34.               bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);   
  35.               ToggleAppBarButton(!isPinned);   
  36.           }   
  37.          this.BottomAppBar.IsSticky = false;   
  38.      } 

 

  以上就完成了,輔助磁貼的添加和顯示。

原文鏈接:http://www.cnblogs.com/akwwl/archive/2013/02/18/2880120.html

 

【編輯推薦】

責(zé)任編輯:彭凡 來源: 博客園
相關(guān)推薦

2021-06-16 09:49:14

Windows 11微軟動(dòng)態(tài)磁貼

2020-03-27 18:00:37

微軟Windows 10操作系統(tǒng)

2015-12-21 10:49:57

Windows 10開始菜單磁貼

2022-01-19 09:37:29

微軟Windows11Windows

2013-04-25 14:15:53

Windows PhoWindows PhoWindows Pho

2014-12-31 16:37:16

win8磁盤自定義ImageVie

2013-04-17 11:21:59

Windows PhoWindows Pho

2022-01-18 06:28:01

Windows 11操作系統(tǒng)微軟

2020-11-02 13:04:46

微軟Windows 10網(wǎng)絡(luò)

2019-07-25 08:19:40

Windows 10系統(tǒng)更新開始菜單

2021-06-16 13:08:14

微軟Windows 10Windows

2021-06-28 19:58:08

微軟Windows 11Windows

2022-01-17 07:10:32

Windows 11操作系統(tǒng)微軟

2015-09-21 09:28:09

開始菜單Build 10547Windows 10

2015-10-14 10:54:25

UWP應(yīng)用SDKWindows 10

2022-11-22 08:17:06

微軟Windows 11

2020-03-20 20:00:05

微軟Windows 10新版變化

2013-04-16 11:31:27

Windows 8.1

2013-05-30 14:00:41

Windows 8.1

2021-06-17 05:28:03

Windows11操作系統(tǒng)微軟
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)