【发布时间】:2018-11-13 10:09:41
【问题描述】:
我正在尝试在某些帧上制作 TapGestureRecognizer,但是当我对其进行测试时,没有任何反应。
xaml
<StackLayout>
<AbsoluteLayout>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="380" TranslationX="12.5" HeightRequest="60" WidthRequest="120">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Sport_Clicked"/>
</Frame.GestureRecognizers>
<StackLayout Orientation="Vertical" Padding="0" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Spacing="-10">
<Label Text="Sport" FontSize="17"/>
</StackLayout>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="380" TranslationX="187.5" HeightRequest="60" WidthRequest="120">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Voeding_Clicked"/>
</Frame.GestureRecognizers>
<StackLayout Orientation="Vertical" Padding="0" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Spacing="-10">
<Label Text="Voeding" FontSize="17"/>
</StackLayout>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="495" TranslationX="12.5" HeightRequest="60" WidthRequest="120">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Slaap_Clicked"/>
</Frame.GestureRecognizers>
<StackLayout Orientation="Vertical" Padding="0" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Spacing="-10">
<Label Text="Slaap" FontSize="17" />
</StackLayout>
</StackLayout>
</Frame>
</AbsoluteLayout>
</StackLayout>
cs
void Sport_Clicked(object sender, EventArgs e)
{
new NavigationPage(new SportPage());
}
void Voeding_Clicked(object sender, EventArgs e)
{
new NavigationPage(new VoedingPage());
}
void Slaap_Clicked(object sender, EventArgs e)
{
new NavigationPage(new SlaapPage());
}
我在测试时没有收到任何警告或错误。是否有与您看不到的帧重叠的东西导致阻止输入?
编辑:
这是使用以下代码的框架的外观
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TranslationY="380" TranslationX="187.5" HeightRequest="60" WidthRequest="120" BackgroundColor="Yellow">
<StackLayout Orientation="Vertical" Padding="0" HorizontalOptions="FillAndExpand" BackgroundColor="Green">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="Voeding_Clicked"/>
</StackLayout.GestureRecognizers>
<StackLayout Orientation="Horizontal" Spacing="-10" BackgroundColor="Red">
<Label Text="Voeding" FontSize="17"/>
</StackLayout>
</StackLayout>
</Frame>
使用此代码,我应该能够单击绿色部分并获得响应,但我没有得到响应?有没有办法让一些东西与整个框架重叠,这样我就可以用它来点击?
【问题讨论】:
-
框架的内容当然会与它重叠,要么将其移动到 StackLayout,要么将其添加到 stacklayout 并保留两者(如果您有较大的边距/填充可以改善总触摸区域.. ..)
-
喜欢这个? pastebin.com/04SU59HG。这也没有用。
-
如果您拥有 Xamarin Inspector(企业许可证),您可以查看是否有东西重叠并阻止触摸输入 docs.microsoft.com/en-us/xamarin/tools/inspector 否则您可以为控件分配不同的背景颜色并这样做... .
-
请查看编辑后的帖子。我没有 Xamarin 检查员。
-
有人有想法吗?