應用程式模型App model

Windows Mixed Reality 使用 通用 Windows 平臺 (UWP) 所提供的應用程式模型,也就是新式 Windows 應用程式的模型和環境。Windows Mixed Reality uses the app model provided by the Universal Windows Platform (UWP), which is a model and environment for modern Windows apps. UWP 應用程式模型定義了如何安全地安裝、更新、設定版本,以及完全移除應用程式。The UWP app model defines how apps are safely installed, updated, versioned, and removed completely. 它也會控制應用程式的生命週期,也就是應用程式執行、睡眠和停止的方式,以及它們如何保留狀態。It also governs the application life cycle - how apps execute, sleep, and stop - and how they can preserve state. 最後,應用程式模型涵蓋與作業系統、檔案和其他應用程式的整合和互動。Finally, the app model covers integration and interaction with the operating system, files, and other apps.

在早餐區域 Windows Mixed Reality 首頁中排列的2D 應用程式2D apps arranged in the Windows Mixed Reality home in a breakfast area
在 Windows Mixed Reality 首頁中排列2D 視圖的應用程式Apps with a 2D view arranged in the Windows Mixed Reality home

應用程式週期App lifecycle

混合現實應用程式的生命週期牽涉到標準應用程式概念,例如放置、啟動、終止和移除。The lifecycle of a mixed reality app involves standard app concepts such as placement, launch, termination, and removal.

放置開始Placement is launch

每個應用程式都是以混合現實的方式啟動,方法是將應用程式磚放 (Windows Mixed Reality 首頁中) 的Windows 次要磚Every app starts in mixed reality by placing an app tile (just a Windows secondary tile) in the Windows Mixed Reality home. 這些應用程式圖格會在放置時開始執行應用程式。These app tiles, on placement, will start running the app. 這些應用程式磚會保存並保持在其放置位置,如同您想要傳回給應用程式的啟動器。These app tiles persist and stay at their placed location, acting like launchers for anytime you want to get back to the app.

放置會將次要磚放在世界中Placement puts a secondary tile in the world
放置會將次要磚放在世界中Placement puts a secondary tile in the world

放置完成之後 (除非應用程式 啟動應用程式啟動) ,否則應用程式會開始啟動。As soon as placement completes (unless the placement was started by an app to app launch), the app starts launching. Windows Mixed Reality 可以一次執行有限數量的應用程式。Windows Mixed Reality can run a limited number of apps at one time. 一旦您放置並啟動應用程式,其他作用中的應用程式可能會暫停。As soon as you place and launch an app, other active apps may suspend. 已暫停的應用程式會在您放置應用程式的任何位置,讓應用程式的上次狀態螢幕擷取畫面。Suspended apps leave a screenshot of the app's last state on its app tile wherever you placed it. 如需處理繼續和其他生命週期事件的詳細資訊,請參閱 WINDOWS 10 UWP 應用程式生命週期For more information on handling resume and other lifecycle events, see Windows 10 UWP app lifecycle.

放置磚之後,應用程式會開始  執行執行、暫停或未執行之應用程式的狀態圖表After placing a tile, the app starts running State diagram for app running, suspended or not running
左方:放置磚之後,應用程式就會開始執行。Right:應用程式執行中、已暫止或未執行的狀態圖表。Left: after placing a tile, the app starts running. Right: state diagram for app running, suspended, or not running.

移除是關閉/終止進程Remove is close/terminate process

當您從世界中移除放置的應用程式磚時,基礎進程會關閉。When you remove a placed app tile from the world, the underlying processes closes. 這有助於確保您的應用程式停止或重新開機有問題的應用程式。This can be useful for ensuring your app is stopped or restarting a problematic app.

應用程式暫停/終止App suspension/termination

Windows Mixed Reality 首頁中,使用者可以從 [開始] 功能表啟動應用程式,並將應用程式磚放在世界中,以建立應用程式的多個進入點。In the Windows Mixed Reality home, the user can create multiple entry points for an app by launching your app from the Start menu and placing the app tile in the world. 每個應用程式磚的行為都是不同的進入點,並且在系統中具有個別的磚實例。Each app tile behaves as a different entry point, and has a separate tile instance in the system. SecondaryTile的查詢會針對每個應用程式實例產生 SecondaryTileA query for SecondaryTile.FindAllAsync will result in a SecondaryTile for each app instance.

當 UWP 應用程式暫停時,會取得目前狀態的螢幕擷取畫面。When a UWP app suspends, a screenshot is taken of the current state.

針對已暫止的應用程式顯示幕幕快照Screenshots are shown for suspended apps
針對已暫止的應用程式顯示幕幕快照Screenshots are shown for suspended apps

另一個 Windows 10 shell 的主要差異在於應用程式如何透過 CoreApplication 來通知應用程式實例啟用 One key difference from other Windows 10 shells is how the app is informed of an app instance activation via the CoreApplication.Resuming and CoreWindow.Activated events.

狀況Scenario 繼續中Resuming 已啟動Activated
從 [開始] 功能表啟動應用程式的新實例Launch new instance of app from the Start menu 以新的 TileId 啟用Activated with a new TileId
從 [開始] 功能表啟動應用程式的第二個實例Launch second instance of app from the Start menu 以新的 TileId 啟用Activated with a new TileId
選取目前未使用的應用程式實例Select the instance of the app that isn't currently active 使用與實例相關聯的 TileId啟用Activated with the TileId associated with the instance
選取不同的應用程式,然後選取先前作用中的實例Select a different app, then select the previously active instance 繼續 引發Resuming raised
選取不同的應用程式,然後選取先前處於非使用中狀態的實例Select a different app, then select the instance that was previously inactive 繼續 引發Resuming raised 然後使用與實例相關聯的 TileId啟用Then Activated with the TileId associated with the instance

擴充執行Extended execution

有時候您的應用程式需要繼續在背景中執行工作或播放音訊。Sometimes your app needs to continue doing work in the background or playing audio. 背景 工作可在 HoloLens 上取得。Background tasks are available on HoloLens.

應用程式可以在背景中執行Apps can run in the background
應用程式可以在背景中執行Apps can run in the background

應用程式檢視App views

當您的應用程式啟動時,您可以選擇您想要顯示的檢視類型。When your app activates, you can choose what type of view you'd like to display. 針對應用程式的 CoreApplication,一律會有主要的 應用程式視圖 ,以及您想要建立的任意數目的應用程式視圖。For an app's CoreApplication, there's always a primary app view and any number of further app views you would like to create. 在桌上型電腦上,您可以將應用程式視圖視為視窗。On desktop, you can think of an app view as a window. 我們的混合現實應用程式範本會建立 Unity 專案,其中主要應用程式視圖為 沉浸式Our mixed reality app templates create a Unity project where the primary app view is immersive.

您的應用程式可以使用 XAML 之類的技術來建立額外的2D 應用程式視圖,以使用應用程式內購買的 Windows 10 功能。Your app can create an extra 2D app view using technology like XAML, to use Windows 10 features such as in-app purchase. 如果您的應用程式啟動為其他 Windows 10 裝置的 UWP 應用程式,您的主要視圖是2D。If your app started as a UWP app for other Windows 10 devices, your primary view is 2D. 不過,您可以藉由新增另一個可輕鬆顯示體驗 volumetrically 的應用程式視圖,在混合現實中「亮亮」。However, you can "light up" in mixed reality by adding another app view that's immersive to show an experience volumetrically. 想像一下以 XAML 建立相片檢視器應用程式,其中的投影片按鈕會切換至沉浸式應用程式視圖,從世界各地的應用程式 flew 相片。Imagine building a photo viewer app in XAML where the slideshow button switched to an immersive app view that flew photos from the app across the world and surfaces.

執行中的應用程式可以有2D 視圖或沉浸式視圖The running app can have a 2D view or an immersive view
執行中的應用程式可以有2D 視圖或沉浸式視圖The running app can have a 2D view or an immersive view

建立沉浸式視圖Creating an immersive view

混合現實應用程式會建立具有 HolographicSpace 類型的沉浸式觀看。Mixed reality apps create an immersive view, which is achieved with the HolographicSpace type.

純粹是沉浸式的應用程式應該一律在啟動時建立沉浸式視圖,即使是從桌面啟動也一樣。An app that is purely immersive should always create an immersive view on launch, even if launched from the desktop. 沉浸式視圖一律會顯示在耳機中,不論其建立位置為何。Immersive views always show up in the headset, regardless of where they were created from. 啟用沉浸式視圖會顯示混合實境入口,並引導使用者進入其耳機。Activating an immersive view will display the Mixed Reality Portal and guide the user to put on their headset.

在桌上型電腦監視器上以2D 視圖開頭的應用程式,可能會建立次要的沉浸式視圖,以顯示耳機中的內容。An app that starts with a 2D view on the desktop monitor may create a secondary immersive view to show content in the headset. 其中一個範例是監視器上的 2D Edge 視窗,會在耳機中顯示360度的影片。An example of this is a 2D Edge window on the monitor displaying a 360-degree video in the headset.

在沉浸式視圖中執行的應用程式只有一個可見的Apps running in immersive view are the only one visible
在沉浸式視圖中執行的應用程式是唯一可見的An app running in an immersive view is the only one visible

Windows Mixed Reality 首頁中的2D 視圖2D view in the Windows Mixed Reality home

沉浸式觀賞以外的任何功能都會轉譯為您世界上的2D 觀點。Anything other than an immersive view is rendered as a 2D view in your world.

在桌上型電腦監視器和耳機中,應用程式可能會有2D 的視圖。An app may have 2D views on both the desktop monitor and in the headset. 新的2D 視圖將放置在與建立它的視圖相同的 shell 中,不論是在監視器上或在耳機中。A new 2D view will be placed in the same shell as the view that created it, either on the monitor or in the headset. 應用程式或使用者目前無法在混合現實首頁與監視器之間移動2D 視圖。It isn't currently possible for an app or a user to move a 2D view between the Mixed Reality home and the monitor.

在 2D view 中執行的應用程式與其他應用程式共用混合世界的空間Apps running in 2D view share the space in the mixed world with other apps
在2D 視圖中執行的應用程式與其他應用程式共用空間Apps running in a 2D view share the space with other apps

其他應用程式磚的位置Placement of additional app tiles

您可以視需要使用 次要磚 api,將多個應用程式放在世界各地的 2d view。You can place as many apps with a 2D view in your world as you want with the Secondary Tile APIs. 這些「釘選」的磚會顯示為使用者必須放置的啟動顯示畫面,之後可用來啟動您的應用程式。These "pinned" tiles will appear as splash screens that users must place and then can later use to launch your app. Windows Mixed Reality 目前不支援將任何2D 磚內容轉譯為動態磚。Windows Mixed Reality doesn't currently support rendering any of the 2D tile content as live tiles.

使用次要磚的應用程式可以有多個放置Apps can have multiple placements using secondary tiles
使用次要磚的應用程式可以有多個放置Apps can have multiple placements using secondary tiles

切換視圖Switching views

從 2D XAML 視圖切換至沉浸式視圖Switching from the 2D XAML view to the immersive view

如果應用程式使用 XAML,則 XAML IFrameworkViewSource 會控制應用程式的第一個視圖。If the app uses XAML, then the XAML IFrameworkViewSource will control the first view of the app. 應用程式必須在啟用 CoreWindow 之前切換至沉浸式觀賞,以確保應用程式直接啟動至沉浸式體驗。The app will need to switch to the immersive view before activating the CoreWindow, to ensure the app launches directly into the immersive experience.

使用 CoreApplication. CreateNewViewApplicationViewSwitcher ,讓它成為使用中的視圖。Use CoreApplication.CreateNewView and ApplicationViewSwitcher.SwitchAsync to make it the active view.


  • 從 XAML 視圖切換至沉浸式視圖時,請勿指定 SwitchAsyncApplicationViewSwitchingOptions ConsolidateViews旗標,或啟動應用程式的平板將從世界中移除。Do not specify the ApplicationViewSwitchingOptions.ConsolidateViews flag to SwitchAsync when switching from the XAML view to the immersive view, or the slate that launched the app will be removed from the world.
  • SwitchAsync 應該使用與您要切換的視圖關聯的 發送器 來呼叫。SwitchAsync should be called using the Dispatcher associated with the view you are switching into.
  • 如果您需要啟動虛擬鍵盤或想要啟用另一個應用程式,則必須 SwitchAsync 回 XAML 視圖。You will need to SwitchAsync back to the XAML view if you need to launch a virtual keyboard or want to activate another app.

 當應用程式進入沉浸式觀賞、混合的世界和其他應用程式消失時,應用程式可以在2d 視圖和沉浸式視圖之間切換Apps can switch between 2D views and immersive views When an app goes into an immersive view, the mixed world and other apps disappear
左方:應用程式可以在2D 視圖和沉浸式視圖之間切換。沒錯:當應用程式進入沉浸式觀看時,Windows Mixed Reality 首頁和其他應用程式會消失。Left: apps can switch between 2D view and immersive view. Right: when an app goes into an immersive view, the Windows Mixed Reality home and other apps disappear.

從沉浸式視圖切換回鍵盤 XAML 視圖Switching from the immersive view back to a keyboard XAML view

在 views 之間來回切換的一個常見原因,是在混合現實應用程式中顯示鍵盤。One common reason for switching back-and-forth between views is displaying a keyboard in a mixed reality app. 只有當應用程式顯示2D 視圖時,shell 才能顯示系統鍵盤。The shell is only able to display the system keyboard if the app is showing a 2D view. 如果應用程式需要取得文字輸入,它可能會提供具有文字輸入欄位的自訂 XAML 視圖、切換至該視窗,然後在輸入完成之後切換回來。If the app needs to get text input, it may provide a custom XAML view with a text input field, switch to it, and then switch back after the input is complete.

如同上一節中所示,您可以使用 ApplicationViewSwitcher SwitchAsync 從您的沉浸式視圖轉換回 XAML 視圖。Like in the previous section, you can use ApplicationViewSwitcher.SwitchAsync to transition back to a XAML view from your immersive view.

應用程式大小App size

2D 應用程式視圖一律會出現在固定的虛擬平板中。2D app views always appear in a fixed virtual slate. 這會讓所有2D 視圖顯示完全相同的內容數量。This makes all 2D views show the exact same amount of content. 以下是應用程式2D 視圖大小的進一步詳細資料:Here are some further details about the size of your app's 2D view:

  • 調整應用程式時,會保留應用程式的外觀比例。The aspect ratio of the app is preserved while resizing.
  • 應用程式 解析度和縮放比例 不會因調整大小而變更。App resolution and scale factor aren't changed by resizing.
  • 應用程式無法在世界中查詢其實際大小。Apps aren't able to query their actual size in the world.

2D 應用程式會以固定的視窗大小顯示2D apps appear with fixed window sizes
具有2D 視圖的應用程式會以固定的視窗大小顯示Apps with a 2D view appear with fixed window sizes

應用程式磚App tiles

此 [開始] 功能表會針對釘 選和所有應用程式 清單,使用標準的小型磚和中等磚。The Start menu uses the standard small tile and medium tile for pins and the All Apps list in mixed reality.

Windows Mixed Reality 的 [開始] 功能表The Start menu for Windows Mixed Reality
Windows Mixed Reality 的 [開始] 功能表The Start menu for Windows Mixed Reality

應用程式與應用程式的互動App to app interactions

當您建立應用程式時,您可以存取 Windows 10 上可用的應用程式通訊機制的豐富應用程式。As you build apps, you have access to the rich app to app communication mechanisms available on Windows 10. 許多新的通訊協定 Api 和檔案註冊在 HoloLens 上都能順利運作,以啟用應用程式啟動和通訊。Many of the new Protocol APIs and file registrations work perfectly on HoloLens to enable app launching and communication.

針對桌上型耳機,與指定副檔名或通訊協定相關聯的應用程式可能是 Win32 應用程式,只能出現在桌面監視器或桌上型電腦平板中。For desktop headsets, the app associated with a given file extension or protocol may be a Win32 app that can only appear on the desktop monitor or in the desktop slate.


HoloLens 透過Windows.System 支援應用程式啟動應用程式 。啟動器 ApiHoloLens supports app to app launching via the Windows.System.Launcher APIs.

啟動另一個應用程式時,需要考慮一些事項:There are some things to consider when launching another application:

  • 執行非強制回應啟動(例如 LaunchUriAsync)時,使用者必須先放置應用程式,才能與其互動。When doing a non-modal launch, such as LaunchUriAsync, the user must place the app before interacting with it.

  • 執行強制回應啟動時(例如透過 LaunchUriForResultsAsync),會將強制回應應用程式放在視窗頂端。When doing a modal launch, such as through LaunchUriForResultsAsync, the modal app is placed on top of the window.

  • Windows Mixed Reality 無法在專屬的視圖上重迭應用程式。Windows Mixed Reality can't overlay applications on top of exclusive views. 為了顯示已啟動的應用程式,Windows 會將使用者帶回世界以顯示應用程式。To show the launched app, Windows takes the user back to the world to display the application.

檔案選擇器File pickers

HoloLens 同時支援 FileOpenPickerFileSavePicker 合約。HoloLens supports both FileOpenPicker and FileSavePicker contracts. 不過,尚未預先安裝任何應用程式來滿足檔案選擇器合約。However, no app comes pre-installed that fulfills the file picker contracts. 例如,您可以從 Microsoft Store 安裝這些應用程式-OneDrive。These apps - OneDrive, for example - can be installed from the Microsoft Store.

如果您已安裝多個檔案選擇器應用程式,您將不會看到任何可供選擇要啟動之應用程式的混淆 UI。If you have more than one file picker app installed, you won't see any disambiguation UI for choosing which app to launch. 相反地,系統會選擇第一個安裝的檔案選擇器。Instead, the first file picker installed will be chosen. 儲存檔案時,會產生包含時間戳記的檔案名。When saving a file, the filename is generated which includes the timestamp. 這無法由使用者變更。This cannot be changed by the user.

根據預設,下列是在本機支援的延伸模組:By default, the following extensions are supported locally:

應用程式App 延伸模組Extensions
照片Photos bmp、gif、jpg、png、avi、mov、的 wmv、wmvbmp, gif, jpg, png, avi, mov, mp4, wmv
Microsoft EdgeMicrosoft Edge htm、html、pdf、svg、xmlhtm, html, pdf, svg, xml

應用程式合約和 Windows Mixed Reality 擴充功能App contracts and Windows Mixed Reality extensions

應用程式合約和擴充點可讓您註冊應用程式,以利用更深入的作業系統功能,例如處理副檔名或使用背景工作。App contracts and extension points allow you to register your app to take advantage of deeper operating system features like handling a file extension or using background tasks. 這是支援和不支援的合約清單,以及 HoloLens 上的擴充點。This is a list of the supported and unsupported contracts and extension points on HoloLens.

合約或延伸模組Contract or Extension 是否支援?Supported?
帳戶圖片提供者 (延伸模組) Account Picture Provider (extension) 不支援Unsupported
警示Alarm 不支援Unsupported
App ServiceApp service 支援但無法完全運作Supported but not fully functional
約會提供者Appointments provider 不支援Unsupported
自動播放 (延伸模組) AutoPlay (extension) 不支援Unsupported
(擴充功能的背景工作) Background tasks (extension) 部分支援的 (並非所有觸發程式都可運作) Partially Supported (not all triggers work)
更新工作 (延伸模組) Update task (extension) 支援Supported
快取檔案更新程式合約Cached file updater contract 支援Supported
(擴充功能的相機設定) Camera settings (extension) 不支援Unsupported
撥號通訊協定Dial protocol 不支援Unsupported
檔案啟用 (延伸模組) File activation (extension) 支援Supported
檔案開啟選擇器協定File Open Picker contract 支援Supported
檔案儲存選擇器協定File Save Picker contract 支援Supported
鎖定螢幕呼叫Lock screen call 不支援Unsupported
媒體播放Media playback 不支援Unsupported
播放至合約Play To contract 不支援Unsupported
預先安裝的設定工作Preinstalled config task 不支援Unsupported
Print 3D 工作流程Print 3D Workflow 支援Supported
(擴充功能) 列印工作設定 Print task settings (extension) 不支援Unsupported
URI 啟用 (延伸模組) URI activation (extension) 支援Supported
受限啟動Restricted launch 不支援Unsupported
搜尋合約Search contract 不支援Unsupported
設定合約Settings contract 不支援Unsupported
共用合約Share contract 不支援Unsupported
SSL/憑證 (延伸模組) SSL/certificates (extension) 支援Supported
Web 帳戶提供者Web account provider 支援Supported

應用程式檔儲存體App file storage

所有儲存體都是透過 Windows. storage 命名空間All storage is through the Windows.Storage namespace. HoloLens 不支援應用程式儲存體同步處理/漫遊。HoloLens doesn't support app storage sync/roaming. 如需詳細資訊,請參閱下列檔:For more information, check out the documentation below:

已知的資料夾Known folders

如需 UWP 應用程式的完整詳細資料,請參閱 KnownFoldersSee KnownFolders for the full details for UWP apps.

屬性Property 在 HoloLens 上支援Supported on HoloLens 在沉浸式耳機上支援Supported on immersive headsets 描述Description
AppCapturesAppCaptures✔️✔️✔️✔️取得應用程式的 [捕獲] 資料夾。Gets the App Captures folder.
CameraRollCameraRoll✔️✔️✔️✔️取得相機翻轉資料夾。Gets the Camera Roll folder.
DocumentsLibraryDocumentsLibrary✔️✔️✔️✔️取得文件庫。Gets the Documents library. 文件庫並非一般用途。The Documents library isn't intended for general use.
MusicLibraryMusicLibrary✔️✔️✔️✔️取得音樂媒體櫃。Gets the Music library.
Objects3DObjects3D✔️✔️✔️✔️取得物件3D 資料夾。Gets the Objects 3D folder.
PicturesLibraryPicturesLibrary✔️✔️✔️✔️取得圖片媒體櫃。Gets the Pictures library.
播放清單Playlists✔️✔️✔️✔️取得播放清單資料夾。Gets the play lists folder.
SavedPicturesSavedPictures✔️✔️✔️✔️取得已儲存的圖片資料夾。Gets the Saved Pictures folder.
VideosLibraryVideosLibrary✔️✔️✔️✔️取得影片庫。Gets the Videos library.
HomeGroupHomeGroup✔️✔️取得家庭家庭資料夾。Gets the HomeGroup folder.
MediaServerDevicesMediaServerDevices✔️✔️取得媒體伺服器的資料夾 (數位生活網路聯盟 (DLNA) # A3 裝置。Gets the folder of media server (Digital Living Network Alliance (DLNA)) devices.
RecordedCallsRecordedCalls✔️✔️取得錄製的呼叫資料夾。Gets the recorded calls folder.
RemovableDevicesRemovableDevices✔️✔️取得「卸載式裝置」資料夾。Gets the removable devices folder.

應用程式套件App package

使用 Windows 10 時,您不再以作業系統為目標,而是將 應用程式的目標設為一或多個裝置系列With Windows 10, you no longer target an operating system but instead target your app to one or more device families. 裝置系列會識別 API、系統特性以及您對於裝置系列中的裝置可以預期的行為。A device family identifies the APIs, system characteristics, and behaviors that you can expect across devices within the device family. 它也會決定您的應用程式可從 Microsoft Store安裝的裝置集合。It also determines the set of devices on which your app can be installed from the Microsoft Store.

  • 若要以桌上型耳機和 HoloLens 為目標,請將應用程式的目標設為 Windows。通用 裝置系列。To target both desktop headsets and HoloLens, target your app to the Windows. Universal device family.
  • 若要以桌面耳機為目標,請將您的應用程式目標設為 Windows desktop 裝置系列。To target just desktop headsets, target your app to the Windows.Desktop device family.
  • 若要以 HoloLens 為目標,請將您的應用程式設定為 Windows 全像裝置系列。To target just HoloLens, target your app to the Windows.Holographic device family.

另請參閱See also