简体   繁体   English

为什么在 UWP 的情况下,网格的 TapGesture 识别器响应缓慢,但在 Android 和 iOS 中工作正常?

[英]Why TapGesture recognizer for Grid is slow to respond in case of UWP but works fine in Android and iOS?

I have a Button and a Grid.我有一个按钮和一个网格。 Button is bind to ExecuteButtonCommand and TapGestureRecognizer for Grid is bind to ExecuteGridCommand. Button 绑定到 ExecuteButtonCommand,TapGestureRecognizer for Grid 绑定到 ExecuteGridCommand。 Now if I press button rapidly and fast, corrresponding label shows correct click counts for all the platforms ie the command code is getting executed for the number of times click happened.现在,如果我快速快速地按下按钮,对应的 label 会显示所有平台的正确点击计数,即命令代码正在执行点击发生的次数。

But in case of Grid, although for android and iOS this works perfectly fine.但是在网格的情况下,虽然对于 android 和 iOS 这工作得很好。 But for UWP, not all the clicks are executing the command.但是对于 UWP 来说,并不是所有的点击都在执行命令。 Example: If I tap the grid rapidly and fast lets say 6 times, then the corresponding label shows only 3 or 4 counts which means command for tapgesture is getting executed less number of times than it actually should.示例:如果我快速点击网格,比如说 6 次,则相应的 label 仅显示 3 或 4 个计数,这意味着用于 tapgesture 的命令执行的次数比实际执行的次数少。

This is what I have in my ViewModel这就是我的 ViewModel 中的内容

<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
        <!-- Place new controls here -->
        <Label Text="{Binding ButtonExecutionCount}" HorizontalOptions="Center"/>
        <Button x:Name="ClickButton" Text="ExecuteClick"  HorizontalOptions="Center"
                    Command="{Binding ExecuteButtonCommand}"
                />
        <Label Text="{Binding GridExecutionCount}" HorizontalOptions="Center"/>
        <Grid BackgroundColor="Aquamarine" VerticalOptions="Center" HorizontalOptions="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Text="Click this grid" Grid.Column="0" Grid.Row="0" HorizontalOptions="Center"/>
            <Grid.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding ExecuteGridCommand}"></TapGestureRecognizer>
            </Grid.GestureRecognizers>
        </Grid>
    </StackLayout>

And here is the code of binding viewmodel that records and displays the click counts:这是记录和显示点击次数的绑定视图模型的代码:

public class MainPageViewModel : INotifyPropertyChanged
    {
        public MainPageViewModel()
        {
            ExecuteGridCommand = new Command(ExecuteGridMethod);
            ExecuteButtonCommand = new Command(ExecuteButtonMethod);
        }

        private int _gridExecutionCount;
        public int GridExecutionCount
        {
            get => _gridExecutionCount;
            set
            {
                _gridExecutionCount = value;
                OnPropertyChanged();
            }
        }

        private int _buttonExecutionCount;
        public int ButtonExecutionCount
        {
            get => _buttonExecutionCount;
            set
            {
                _buttonExecutionCount = value;
                OnPropertyChanged();
            }
        }

        public Command ExecuteGridCommand { get; set; }

        public Command ExecuteButtonCommand { get; set; }


        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string name = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }

        public void ExecuteGridMethod()
        {
            GridExecutionCount++;
        }

        public void ExecuteButtonMethod()
        {
            ButtonExecutionCount++;
        }
    }

Here I have cliked both 5 times and for button count is fine but for grid in UWP it is less that actual clicks.在这里,我已经点击了 5 次,按钮计数很好,但对于 UWP 中的网格,实际点击次数要少。

在此处输入图像描述

Cause: The strange behavior in your project was caused by the version of Xamarin.Forms.原因:您的项目中的奇怪行为是由Xamarin.Forms的版本引起的。 It is an existing issue in the version 4.5.x .这是4.5.x版本中的一个现有问题。

Solution: The issue had been fixed in the latest version ( 4.7.x ).解决方案:该问题已在最新版本( 4.7.x )中修复。 I tested your sample on it and works fine.我在上面测试了你的样品并且工作正常。 So you just need to update the version of XF both in share project and platform projects to the latest version.因此,您只需要将共享项目和平台项目中的 XF 版本更新到最新版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么此UWP ComboBox在初始化后可以为空白,但可以很好地进行选择? - Why this UWP ComboBox can be blank after initialization but works fine for selection? iOS中的AES填充问题,但在Android中工作正常 - AES Padding issue in iOS but works fine in Android 在iOS上为ListView设置ItemSource崩溃,在Android中工作正常 - Setting ItemSource for ListView crashes on iOS, works fine in Android Xamarin Project在Android中工作正常,调用WCF时在UWP中引发“ 405”错误 - Xamarin Project works fine in Android, throws “405” errors in UWP when calling WCF (HttpResponseMessage response = await client.GetAsync(url))在uwp上工作正常,但在android上不行 - (HttpResponseMessage response = await client.GetAsync(url)) works fine with uwp but not on android Xamarin Forms - Android 上的进度条未更新。 在 UWP 上工作正常 - Xamarin Forms - Progress Bar doesn't update on Android. Works fine on UWP SignalR 在 UWP 中运行缓慢而在控制台应用程序中运行速度快 - SignalR works slow in UWP and fast in console application UWP中的捏手势识别器 - Pinch gesture recognizer in uwp Android和iOS上的UWP - UWP on Android and iOS UWP 样式 X:将边距绑定到 function 会引发 System.AccessViolationException。 任何想法为什么,如果在内联 xaml 中设置时这工作正常? - UWP Style X:binding of margin to a function throws a System.AccessViolationException. Any ideas why, when this works fine if set in inline xaml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM