我试图在某些帧上制作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>
使用此代码,我应该能够单击绿色部分并获得响应,但我没有得到它?有没有办法让整个框架重叠的东西,所以我可以用它点击?
最佳答案 原因:
您的相框不响应您的TapGestureRecognizer是由您的TranslationY =“380”TranslationX =“187.5”属性引起的.即使看到此控件,也无法点击超出父视图范围的控件.
Translating an element outside the bounds of its parent container may
prevent inputs from working.
解:
删除TranslationY和TranslationX属性并以其他方式布置框架.
编辑:
您可以在下面看到屏幕截图,我编写了一个简单的演示并将PaleGreen添加为AbsoluteLayout的backgroundColor.你的Frame超出了父视图的范围.所以它不会对TapGestureRecognizer做出响应.
因此,将FillAndExpand设置为AbsoluteLayout的VerticalOptions属性,以确保您的Frame位于父视图的边界内.
<AbsoluteLayout BackgroundColor="PaleGreen" VerticalOptions="FillAndExpand">
我在这里更新了截图,希望你能理解: