专栏首页林德熙的博客UWP how to get the touch width

UWP how to get the touch width

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.

    <Grid Background="Transparent">

    </Grid>

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

        public MainPage()
        {
            InitializeComponent();

            Content.PointerMoved += MainPage_PointerMoved;
        }

        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {

        }

We can use GetCurrentPoint to get the PointerPoint.

        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.

        private void MainPage_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(this);
            Rect rect = point.Properties.ContactRect;
        }

To get the touch width.

        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.

        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 ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • WPF will break when an exception be throw in the StylusPlugIn

    We can write a class that inherits the StylusPlugIn. And this class can get the ...

    林德熙
  • 如何让 USB 设备不显示安全删除硬件弹出选项

    插入一个 U 盘的时候,可以在右下角找到安全删除硬件图标,点击就可以删除此硬件。如果此时插入的是一个无线网卡,也就是 USB 无线 wifi 设备,此时如果逗比...

    林德熙
  • WPF shows that some windows in multithreading will be locked in the PenThreadWorker constructor when

    Problem description: WPF will initialize pen thread when the window initializing...

    林德熙
  • 【CodeForces 489A】SwapSort

    In this problem your goal is to sort an array consisting of n integers in at mos...

    饶文津
  • Codeforces 810C Do you want a date?(数学,前缀和)

    C. Do you want a date? time limit per test:2 seconds memory limit per test:256 m...

    Angel_Kitty
  • HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3276...

    Angel_Kitty
  • Python Unicode HOWTO

    character, code point, glyph[glɪf], encoding

    py3study
  • 将算法进一步开发吗?手把手教你搭建基于CNN模型的Flask Web应用

    对于机器学习和人工智能研究人员而言,好多人都只是构建好模型后就没有进一步处理了,停留在一个比较粗糙的模型上面,没有将其变成一个产品,其实好多创业型人工智能公司都...

    用户3578099
  • 生成面要素的中心点-GDAL

    也许是我打开方式有问题吧,我搜索了接近两个小时,百度、必应、谷歌,都试了一遍,但没啥收获!

    数据处理与分析
  • 如果有人问你Java虚拟机执行线程同步及Synchronized实现原理,你就把这篇文章分享给他。

    在讲解Synchronized的实现原理之前,我们先了解一下Java虚拟机是如何执行线程同步的。

    格姗知识圈

扫码关注云+社区

领取腾讯云代金券