前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >UWP how to get the touch width

UWP how to get the touch width

作者头像
林德熙
发布2019-03-13 16:10:06
6690
发布2019-03-13 16:10:06
举报
文章被收录于专栏:林德熙的博客林德熙的博客

The touch width can help us to make a gorgeous application. This article tells you how to get the touch width from the PointEvent in UWP.

Opening the VisualStudio and create an empty UWP application.

We should open the MainPage.xaml and add the background in the Grid to make the Grid can get the PointMove event.

代码语言:javascript
复制
    <Grid Background="Transparent">

    </Grid>

Then we can open the MainPage.xaml.cs to write the code to get the PointerMove event.

代码语言:javascript
复制
        public MainPage()
        {
            InitializeComponent();

            Content.PointerMoved += MainPage_PointerMoved;
        }

        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {

        }

We can use GetCurrentPoint to get the PointerPoint.

代码语言:javascript
复制
        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(this);
        }

And we can find the ContactRect in Properties. We can get the touch width from ContactRect.

代码语言:javascript
复制
        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(this);
            Rect rect = point.Properties.ContactRect;
        }

To get the touch width.

代码语言:javascript
复制
        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(this);
            Rect rect = point.Properties.ContactRect;
            Debug.WriteLine($"Touch rect width={rect.Width},height={rect.Height}");
        }

We also can use ContactRectRaw in Properties.

代码语言:javascript
复制
        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(this);
            Rect rect = point.Properties.ContactRect;
            Debug.WriteLine($"Touch rect width={rect.Width},height={rect.Height}");
            rect = point.Properties.ContactRectRaw;
            Debug.WriteLine($"Touch raw rect width={rect.Width},height={rect.Height}");
        }

Try to run the code and touch the application and you can watch the output windows that prints the touch width.


本文会经常更新,请阅读原文: https://lindexi.gitee.io/post/UWP-how-to-get-the-touch-width.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

知识共享许可协议
知识共享许可协议

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://lindexi.gitee.io ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档