设为首页 收藏本站
查看: 1114|回复: 0

win8 app 鼠标操作和多点操作

[复制链接]

尚未签到

发表于 2015-5-21 10:12:44 | 显示全部楼层 |阅读模式
  win8支持多点触摸技术,而我们在屏幕上所做的各种操作,也最终转换为输入
  http://code.msdn.microsoft.com/windowsapps/Input-3dff271b
  http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh465387#using_manipulation_events
  在window runtime上响应触屏事件的方法分为两类:单点和多点。下面分别介绍:

  鼠标操作事件:
  PointerWheelChanged :鼠标滚轮转动时发生
  PointerPressed :鼠标点击下去的时候即触发事件。
PointerReleased :鼠标点击下去的时候释放鼠标时触发事件。
PointerMoved :鼠标在有效范围之内移动之时触发事件。
PointerEntered :鼠标进入有效范围之时触发一次。
PointerExited :鼠标退出有效范围之时触发事件。  
  这些事件的参数都是 PointerRoutedEventArgs
  
  多点事件包括:
  ManipulationStarting      
ManipulationStarted        
ManipulationInertiaStarting
ManipulationDelta
ManipulationCompleted      

  当多点操作时,一般先触发 ManipulationStarted  事件,然后是一连串的ManipulationDelta事件触发,最后是ManipulationCompleted  事件.
  注意实现多点操作的时候要设置多点操作对象的 ManipulationMode 属性

  http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh465387#using_manipulation_events
  
  下面看一个示例:





        
        
            
               
            
            
        
   

  


///
    /// An empty page that can be used on its own or navigated to within a Frame.
    ///
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            this.LayoutRoot.DoubleTapped += LayoutRoot_DoubleTapped;

            this.OpeningMessage.Tapped += OpeningMessage_Tapped;
            this.Photo.Tapped+=Photo_Tapped;
            
            this.Photo.ManipulationMode=ManipulationModes.All;
            this.Photo.ManipulationDelta+=Photo_ManipulationDelta;
        }

        ///
        /// Invoked when this page is about to be displayed in a Frame.
        ///
        /// Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        async private void OpeningMessage_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Display a FileOpenPicker and allow the user to select a photo
            var picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".gif");
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            var file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var stream = await file.OpenAsync(FileAccessMode.Read);

                // Wrap a WriteableBitmap around the selected photo and display it
                WriteableBitmap bitmap = new WriteableBitmap(1, 1);
                bitmap.SetSource(stream);
                Photo.Source = bitmap;

                // Reset the CompositeTransform
                PhotoTransform.TranslateX = PhotoTransform.TranslateY = 0.0;
                PhotoTransform.ScaleX = PhotoTransform.ScaleY = 1.0;

                // Hide the "Tap here" message in case it hasn't been removed already
                OpeningMessage.Visibility = Visibility.Collapsed;
            }
        }

        private void Photo_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            // Translate the photo
            PhotoTransform.TranslateX += e.Delta.Translation.X;
            PhotoTransform.TranslateY += e.Delta.Translation.Y;

            // Scale the photo
            PhotoTransform.ScaleX *= e.Delta.Scale;
            PhotoTransform.ScaleY *= e.Delta.Scale;

            // Constrain scale factor
            PhotoTransform.ScaleX = Math.Min(PhotoTransform.ScaleX, 4.0);
            PhotoTransform.ScaleY = Math.Min(PhotoTransform.ScaleY, 4.0);
            PhotoTransform.ScaleX = Math.Max(PhotoTransform.ScaleX, 1.0);
            PhotoTransform.ScaleY = Math.Max(PhotoTransform.ScaleY, 1.0);
        }

        private void LayoutRoot_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            // Reset the CompositeTransform
            PhotoTransform.TranslateX = PhotoTransform.TranslateY = 0.0;
            PhotoTransform.ScaleX = PhotoTransform.ScaleY = 1.0;
        }

        private void Photo_Tapped(object sender, TappedRoutedEventArgs e)
        {

        }
    }  
DSC0000.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-69102-1-1.html 上篇帖子: win8 app AppBar中使用ToggleButton 下篇帖子: win8 mysqlzip install
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表