如何為Surface Dial裝置開發自訂互動功能

來源:互聯網
上載者:User

標籤:img   計算   led   響應   pre   hang   main   ros   ann   

隨著Surface Studio的發布,微軟發布了與之相配套的外設硬體Surface Dial,使用者可以將Surface Dail吸附在Surface Studio的螢幕上面,用旋轉和點擊的實體操作來操作應用程式。

 

目前Surface Dial 可以支援的終端硬體有三款:

  • Surface Studio
  • Surface Book
  • Surface Pro 4

有上述之一硬體的小夥伴們可以嘗試一下這款新鮮的產品。

 

下面,我用一款簡單的UWP程式來介紹如何給Surface Dial這款外設開發自訂的互動邏輯。

 

前期準備:

  • 請確保您的電腦作業系統是最新的Win10 Anniversary Update版本
  • 請確保您的Visual Studio是VS2015 update3 版本
  • Surface Dial裝置(可選)
  • Surface Studio, Surface Book 以及 Surface Pro 4 都是可選項,如果沒有,並不影響案例代碼的運行

 

運行例子:

如果您有surface dial裝置,並且擁有Surface Studio, Surface Book或者Surface Pro4其中的任一一款終端,請在Visual Studio裡面運行我們的案例代碼,並且將Surface Dail吸附在螢幕上。您將會看到下面這個介面。

此時,您可以選擇Surface Dial,介面中的滑動條會跟著您的轉動而變化,點擊Surface Dial的按鈕,介面中的開關控制項會開啟或者關閉。

 

使用代碼:

您可以使用代碼去自訂Surface Dail在您的應用程式裡的旋轉和點擊操作。

控制Surface Dail的核心類是RadialController ,可以在Windows.UI.Input這個名字空間下找到該類。您可以調用RadialController.CreateForCurrentView() 來擷取該類的實體。

 

RadialController類實體對外公布了幾個事件,在這個例子裡我們只關注ButtonClicked 事件和 RotationChanged事件。前者會在Surface Dail被點擊的時候調用,而後者則是響應旋轉操作。

 

下面是例子裡的核心程式碼片段:

    public sealed partial class MainPage : Page     {         RadialController rdController = null;         public MainPage()         {             this.InitializeComponent();              // get controller             rdController = RadialController.CreateForCurrentView();              // process click event             rdController.ButtonClicked += RdController_ButtonClicked;              // process rotate event             rdController.RotationChanged += RdController_RotationChanged;         }          private void RdController_RotationChanged(RadialController sender, RadialControllerRotationChangedEventArgs args)         {             // change the slider according to the delta degree from rotating             var deltaRatio = args.RotationDeltaInDegrees / 360.0f;             this.slider.Value += this.slider.Maximum * deltaRatio;         }          private void RdController_ButtonClicked(RadialController sender, RadialControllerButtonClickedEventArgs args)         {             // switch the toggle to opposite status             this.btnToggle.IsOn = !this.btnToggle.IsOn;         }     }

 

最後,您可以通過訪問 How to implement custom interactions for Surface Dial 來下載完整的代碼案例。

 

如何為Surface Dial裝置開發自訂互動功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.