【发布时间】:2022-11-01 14:20:50
【问题描述】:
我正在为 LongPress 使用 xamarin 社区工具包,为 PinchGestureRecognizer 使用 GestureRecognizers。 PinchGestureRecognizer 完成后,xct:TouchEffect.LongPressCommand 也会被触发。有没有办法一次触发这些事件?
这是我的代码示例
<StackLayout
xct:TouchEffect.LongPressCommand="{Binding LongPressCommand}"
xct:TouchEffect.LongPressCommandParameter="LongPress"
BackgroundColor="Red">
<Frame
Padding="24"
BackgroundColor="#2196F3"
CornerRadius="0">
<Label
FontSize="36"
HorizontalTextAlignment="Center"
Text="Welcome to Xamarin.Forms!"
TextColor="White" />
</Frame>
<Label
Padding="30,10,30,10"
FontSize="Title"
Text="Start developing now" />
<Label
Padding="30,0,30,0"
FontSize="16"
Text="Make changes to your XAML file and save to see your UI update in the running app with XAML Hot Reload. Give it a try!" />
<Label Padding="30,24,30,0" FontSize="16">
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="Learn more at " />
<Span FontAttributes="Bold" Text="https://aka.ms/xamarin-quickstart" />
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<StackLayout.GestureRecognizers>
<PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</StackLayout.GestureRecognizers>
</StackLayout>
cs 文件
public ICommand LongPressCommand { get; set; }
public MainPage()
{
InitializeComponent();
LongPressCommand = new Command<string>(LongPress);
BindingContext = this;
}
public void LongPress(string flag)
{
}
private void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
{
}
}
【问题讨论】:
-
您可能需要在
OnPinchUpdated期间保存当前时间。然后在LongPress中,检查距离最近的OnPinchUpdated已经过去了多少时间。如果经过的时间“太短”(可能是 250 毫秒?尝试不同的值),则忽略LongPress。
标签: xamarin xamarin.forms xamarin.android xamarin-community-toolkit