简单的页面内容:包含框架和一些按钮的外部布局。框架包含stackLayout,stacklayout内部是一些标签。
<ContentPage.Content>
<StackLayout x:Name="outLayout">
<Frame x:Name="frame"
HasShadow="True"
BackgroundColor="White"
OutlineColor="Gray"
Margin="16,0,16,0">
<StackLayout x:Name="innerLayout" BackgroundColor="Red">
<Label Text="Testing" FontAttributes="Bold" FontSize="Large" InputTransparent="True"/>
<Label Text="Testing" FontSize="Small" InputTransparent="True"/>
</StackLayout>
</Frame>
<Button Text="Frame handle tap event" Clicked="Button_Clicked"></Button>
<Button Text="inner Layout handle tap event" Clicked="Button_Clicked_1"></Button>
<Button Text="out layout handle tap event" Clicked="Button_Clicked_2" />
</StackLayout>
</ContentPage.Content>
代码隐藏我有一个TapGesture事件,如果点击某个视图,只需记录一条消息。
public TestInputTransparent()
{
InitializeComponent();
var tapGesture = new TapGestureRecognizer();
tapGesture.Tapped += TapGesture_Tapped;
innerLayout.GestureRecognizers.Add(tapGesture);
frame.GestureRecognizers.Add(tapGesture);
outLayout.GestureRecognizers.Add(tapGesture);
}
private void TapGesture_Tapped(object sender, EventArgs e)
{
if (sender is StackLayout) {
Debug.WriteLine(" stacklayout Tapped");
} else if (sender is Frame) {
Debug.WriteLine( " frame Tapped");
}
}
private void Button_Clicked(object sender, EventArgs e)
{
innerLayout.InputTransparent = true;
}
private void Button_Clicked_1(object sender, EventArgs e)
{
innerLayout.InputTransparent = false;
}
private void Button_Clicked_2(object sender, EventArgs e)
{
frame.InputTransparent = true;
}
我的期望是任何tap事件都将由out stackLayout处理,无论out stackLayout的子节点是否收到tap事件。
当我点击按钮&#34;框架手柄点击事件&#34;时,我设置了innerLayout.InputTransparent = true;
,因此点击事件将由帧处理。我可以通过单击第二个按钮将其设置回来。但是当我设置frame.InputTransparent = true;
时,点击事件仍然留在框架元素中。帧不会交给out stackLayout。为什么?框架是特例吗?