像是 WinUI 3 應用程式 (使用 Windows 應用程式 SDK) 這類桌面應用程式,或是 Windows Presentation Foundation (WPF) 或 Windows Forms (WinForms) 應用程式,可以透過使用封裝應用程式來釘選次要磚 (請參閱從您的程式碼建置 MSIX 套件)。 此方法舊稱為傳統型橋接器。
重要
需要 Fall Creators Update:您必須以 SDK 16299 為目標,並執行組建 16299 或更新版本,才能從傳統型橋接器應用程式釘選次要磚。
<PropertyGroup>
<!-- You can also target other versions of the Windows SDK and .NET; for example, "net6.0-windows10.0.19041.0" -->
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
</PropertyGroup>
// Initialize the tile with required arguments
var tile = new Windows.UI.StartScreen.SecondaryTile(
"myTileId5391",
"Display name",
"myActivationArgs",
new Uri("ms-appx:///Assets/Square150x150Logo.png"),
TileSize.Default);
// Initialize the tile with required arguments
var tile = new Windows.UI.StartScreen.SecondaryTile(
"myTileId5391",
"Display name",
"myActivationArgs",
new Uri("ms-appx:///Assets/Square150x150Logo.png"),
TileSize.Default);
var wih = new System.Windows.Interop.WindowInteropHelper(this);
var hWnd = wih.Handle; // For a WinForms window object, access the NativeWindow.Handle property instead.
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)tile;
initWindow.Initialize(hWnd);
最後,要求釘選磚,方法與一般 UWP 應用程式相同。
// Pin the tile
bool isPinned = await tile.RequestCreateAsync();
// Here, update UI to reflect whether user can now either unpin or pin