注:本文說起到的代碼示例下載地址 > How to build an "Hello World" 2D app in HololLens.html
HoloLens 是微軟的一款MR Glass(混合現實全息眼鏡), 國內某非著名SQ主播出了個片子介紹它,有興趣的點這裏:http://v.youku.com/v_show/id_XMTcxNjIzNzQ2MA==.html?from=y1.7-1.2shell
HoloLens中可用的App大體分爲兩種類型:express
開發的前期準備:windows
一切準備穩當,讓咱們來開始建立一個HoloLens的2D Hello World程序:api
1.首先咱們來先造一個筏子→_→,打開VS 並建立一個UWP app。app
2.打開MainPage.xaml,貼入以下代碼:ui
1 <Page 2 x:Class="HololensApp.MainPage" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:HololensApp" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d"> 9 10 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 11 <StackPanel> 12 <StackPanel Orientation="Horizontal"> 13 <TextBlock Text="Click count:" /> 14 <TextBlock Text="{Binding ClickCount}" /> 15 </StackPanel> 16 <Button Click="Button_Click">Click Me</Button> 17 </StackPanel> 18 </Grid> 19 </Page>
在CS代碼中貼入以下代碼:this
public sealed partial class MainPage : Page { public MainPageViewModel ViewModel = new MainPageViewModel(); public MainPage() { this.InitializeComponent(); this.DataContext = ViewModel; } private void Button_Click(object sender, RoutedEventArgs e) { ViewModel.ClickCount++; } } public class MainPageViewModel : BindableBase { private int _clickCount; public int ClickCount { get { return _clickCount; } set { SetProperty(ref _clickCount, value); } } } [Windows.Foundation.Metadata.WebHostHidden] public abstract class BindableBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null) { if (object.Equals(storage, value)) return false; storage = value; this.OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }
修復掉引用錯誤:在劃紅線的位置點擊,出現小燈泡後選擇小燈泡裏的選項便可。spa
3.而後選擇調試環境(這裏你須要安裝HoloLens 模擬器)3d
3.而後按F5鍵,開始跑程序。
這時模擬器就會啓動而且部署你的app到模擬器,模擬器比較慢,耐心等待一段時間,
當程序運行起來後,你能夠看到以下界面:
在app窗體上右鍵向上拖動以固定改App,此時app纔算是真正運行起來:
使用W,A,S,D和上下左右鍵移動中間的圓點到按鈕上並按空格鍵,能夠發現上面的數字顯示你點擊的次數:
到此,該演示就結束了,是否是有種受騙上當的感受?TMD這不就是UWP嗎?
是的,其實他就是UWP,只是閹割版而已,重說三:閹割版,閹割版,閹割版,也就是有些UWP的特性在HoloLens現階段中是不支持的,這一點纔是真正須要你注意的地方。詳細的列表請查閱微軟官方文檔:Current limitations for apps using APIs from the shell
HoloLens 3D入門教程請戳http://www.cnblogs.com/onecodeonescript/p/5925906.html