Shake Gestures Library 應用

  • 911
  • 0
  • 2014-01-21

摘要:Shake Gestures Library 應用

前幾天在研究Windows Phone 的時候,發現了有不少的APP都有加入Shake的功能。

 

然後小編我就很喜歡這種功能,於是就上網Google了一些文章在這邊要來與大家分享。

 

這篇文章中小編將介紹Windows Phone的Shake功能。

 

步驟一:你需要到http://create.msdn.com/en-us/education/catalog/article/Recipe_Shake_Gesture_LibraryStep

下載檔案下來。

 

步驟二:解壓縮後在\ShakeGestures\ShakeGesturesSample\Bin\Debug裡面找到ShakeGestures.dll

 

步驟三:開啟你建立好的專案,在專案總管裡面按右鍵把它加入參考裡。

 

到這裡已經完成一半了,接下來就可以開始始用它了。

 

步驟四:開啟你的cs檔,然後要把ShakeGestures.dll引入


using ShakeGestures;

 

步驟五:在MainPage()中我們要註冊震動事件


ShakeGesturesHelper.Instance.ShakeGesture += new EventHandler(Instance_ShakeGesture);

設置所需搖晃次數,小編這邊是設置兩次


ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 2;        

最後加入下段程式碼,讓它開始檢測


ShakeGesturesHelper.Instance.Active = true;

 

步驟六:加入Instance_ShakeGesture,裡面就可以做讀者想做的事情,小編這邊是改變TextBlock的值。


        private void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
        {
            this.Dispatcher.BeginInvoke(() =>
            {
                txtShake.Text = String.Format("Shaked Axis = {0}", e.ShakeType);
            });
        }

 

結果:使用不同方向搖晃手機就會顯示三種方位的值,分別為 X 、Y 、Z 。