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

UWP how to get the touch width

作者头像
林德熙
发布2022-08-04 14:20:43
5620
发布2022-08-04 14:20:43
举报
文章被收录于专栏:林德熙的博客

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.

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

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

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

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

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