共用方式為


將次要磚釘選到開始

注意

生活磚是較新版本 Windows 不支援的 Windows 10 功能。 針對新的應用程式,建議您遵循應用程式圖示的目前指引

本主題將逐步引導您完成為 Windows 應用程式建立次要磚,並將它釘選到 [開始] 功能表的步驟。

次要磚的螢幕快照

若要進一步了解次要磚,請參閱次要磚概觀

新增命名空間

Windows.UI.StartScreen 命名空間包含 SecondaryTile 類別。

using Windows.UI.StartScreen;

初始化次要磚

次要磚是由幾個主要元件所組成...

  • TileId:唯一識別碼,可讓您在其他次要磚之間識別此磚。
  • DisplayName:您要在磚上顯示的名稱。
  • 引數:您要在使用者按一下磚時傳回應用程式的引數。
  • Square150x150Logo:必要標誌,顯示於中型磚上 (若未提供小型標誌,則會調整為小型磚的大小)。

必須提供上述所有屬性的初始化值,否則將會收到例外狀況。

您可以使用各種不同的建構函式,但使用 採用、 displayNamearguments、 和 square150x150Logo的建構函tileId式,可desiredSize協助您設定所有必要的屬性。

// Construct a unique tile ID, which you will need to use later for updating the tile
string tileId = "City" + zipCode;

// Use a display name you like
string displayName = cityName;

// Provide all the required info in arguments so that when user
// clicks your tile, you can navigate them to the correct content
string arguments = "action=viewCity&zipCode=" + zipCode;

// Initialize the tile with required arguments
SecondaryTile tile = new SecondaryTile(
    tileId,
    displayName,
    arguments,
    new Uri("ms-appx:///Assets/CityTiles/Square150x150Logo.png"),
    TileSize.Default);

選用:新增大型磚大小的支援

如果您要在次要磚上顯示豐富的磚通知,則可能會想要允許使用者將其磚調整為寬版或大型,如此使用者就能看見更多的內容。

若要啟用寬版和大型磚大小,您必須提供 Wide310x150LogoSquare310x310Logo。 此外,您應盡可能為小型磚大小提供 Square71x71Logo (否則我們會縮小您所需的 Square150x150Logo 以用於小型磚)。

您也可以提供獨特的 Square44x44Logo,並選擇讓它在通知出現時顯示於右下角。 如果您未提供,則會改用您主要磚中的 Square44x44Logo

// Enable wide and large tile sizes
tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/CityTiles/Wide310x150Logo.png");
tile.VisualElements.Square310x310Logo = new Uri("ms-appx:///Assets/CityTiles/Square310x310Logo.png");

// Add a small size logo for better looking small tile
tile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/CityTiles/Square71x71Logo.png");

// Add a unique corner logo for the secondary tile
tile.VisualElements.Square44x44Logo = new Uri("ms-appx:///Assets/CityTiles/Square44x44Logo.png");

選用:啟用顯示顯示名稱

顯示名稱預設為「不」顯示。 若要在中型/寬版/大型上顯示顯示名稱,請新增下列程式碼。

// Show the display name on all sizes
tile.VisualElements.ShowNameOnSquare150x150Logo = true;
tile.VisualElements.ShowNameOnWide310x150Logo = true;
tile.VisualElements.ShowNameOnSquare310x310Logo = true;

選用:3D 次要磚

您可以新增 3D 資產來增強用於 Windows Mixed Reality 的次要磚。 使用者可在混合實境環境中使用您的應用程式時,直接將 3D 磚放入其 Windows Mixed Reality 首頁而非 [開始] 功能表。 例如,您可以建立 360° 全景照來直接連結至 360° 相片檢視器應用程式,或讓使用者從傢俱型錄中放置椅子的 3D 模型,以便在選取該物件時,開啟其相關定價和色彩選項的詳細資料頁面。 若要開始使用,請參閱混合實境開發人員文件

釘選次要磚

最後,要求釘選磚。 請注意,此操作必須從 UI 執行緒呼叫。 在 Desktop 上會出現一個對話方塊,要求使用者確認是否要釘選磚。

重要

針對使用 傳統型橋接器 的桌面應用程式,您必須先執行額外的步驟,如從傳統型應用程式釘選中所述

// Pin the tile
bool isPinned = await tile.RequestCreateAsync();

// TODO: Update UI to reflect whether user can now either unpin or pin

查看次要磚是否存在

如果您的使用者瀏覽應用程式中已釘選到 [開始] 的頁面,您會希望改為顯示 [取消釘選] 按鈕。

因此,當選擇要顯示的按鈕時,您必須先查看次要磚目前是否已釘選。

// Check if the secondary tile is pinned
bool isPinned = SecondaryTile.Exists(tileId);

// TODO: Update UI to reflect whether user can either unpin or pin

取消釘選次要磚

如果磚目前已釘選,且使用者按一下 [取消釘選] 按鈕,則是要取消釘選 (刪除) 磚。

// Initialize a secondary tile with the same tile ID you want removed
SecondaryTile toBeDeleted = new SecondaryTile(tileId);

// And then unpin the tile
await toBeDeleted.RequestDeleteAsync();

更新次要磚

如果您需要更新次要磚上的標誌、顯示名稱或其他任何專案,您可以使用 RequestUpdateAsync

// Initialize a secondary tile with the same tile ID you want to update
SecondaryTile tile = new SecondaryTile(tileId);

// Assign ALL properties, including ones you aren't changing

// And then update it
await tile.UpdateAsync();

列舉所有釘選的次要磚

如果您需要探索使用者已釘選的所有磚,而不是使用 SecondaryTile.Exists,您也可以使用 SecondaryTile.FindAllAsync

// Get all secondary tiles
var tiles = await SecondaryTile.FindAllAsync();

傳送磚通知

若要了解如何透過磚通知在磚上顯示豐富的內容,請參閱傳送本機磚通知