zoukankan      html  css  js  c++  java
  • wp摇一摇功能

    在这篇文章中我们将介绍 Windows Phone 的摇晃功能。让我们来看如何实现。

     
     
    Step 2: 解压后进入 ShakeGesture 的 debug 文件夹
     
     
     
    Step 3: 创建一个 Sliverlight for Windows Phone 项目
     
    Step 4: 将 ShakeGestures dll 添加到项目中
     
     
     
    Step 5: 在 MainPage.xaml 中添加 TextBlock
     
    1
    <TextBlock Text="" Height="60" HorizontalAlignment="Left" Margin="100,100,0,0" Name="txtShakeType" VerticalAlignment="Top" FontSize="40" />
    Step 6: 引入 ShakeGestures.
     
    1
    using ShakeGestures;
    Step 7: 修改 MainPage.xaml.cs 中的构造器,代码如下。MinimumRequiredMovesForShake 设置为 2 表示需要在同一个方向摇晃两次
    1
    public MainPage()
    2
    {
    3
       InitializeComponent();
    4
       ShakeGesturesHelper.Instance.ShakeGesture += new EventHandler<ShakeGestureEventArgs>(Instance_ShakeGesture);
    5
       ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 2;
    6
       ShakeGesturesHelper.Instance.Active = true;
    7
    }
    Step 8: Instance_ShakeGesture 用于摇晃时更新 UI 显示:
     
    1
    private void Instance_ShakeGesture(object sender, ShakeGestureEventArgs e)
    2
    {
    3
       this.Dispatcher.BeginInvoke(() =>
    4
       {
    5
          txtShakeType.Text = String.Format("Shaked Axis = {0}", e.ShakeType);
    6
       });
    7
    }
    Step 9: 现在运行程序,然后使用不同的方向摇晃手机,设备上将会显示不同轴的摇晃信息:
  • 相关阅读:
    第三周学习进度
    计算最低价格
    第二阶段冲刺5
    第二阶段冲刺4
    第十三周进度条
    第二阶段冲刺3
    寻找小水王
    第二阶段冲刺2
    第二阶段冲刺1
    构建之法阅读笔记
  • 原文地址:https://www.cnblogs.com/greywolf/p/3008456.html
Copyright © 2011-2022 走看看