单击其他控件下方的控件

3

我有一个Xamarin Forms页面,在末尾有一个StackLayout覆盖整个屏幕,只有在调用它时才可见。

StackLayout可以正确显示,ActivityIndicator也是如此。但是,我仍然可以单击任何应该位于StackLayout下方的控件。

这是预期行为吗?在WPF或类似平台上,当我把一个控件放在另一个控件前面时,不允许单击其后面的控件。

XAML:

<Grid>
      <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <Image Source="Background.png" Aspect="AspectFill"></Image>
      <StackLayout Padding="10, 10, 0, 0">
          <Image Source="Logo.png" WidthRequest="200" HorizontalOptions="Start" />
      </StackLayout>
      <RelativeLayout>
      <StackLayout x:Name="ContentContainer" BackgroundColor="Black" Opacity="0.7" Orientation="Vertical"
               RelativeLayout.XConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Width,
                                    Factor=0}"
               RelativeLayout.YConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Height,
                                    Factor=0.33}"
               RelativeLayout.WidthConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Width,
                                    Factor=1.00}"
               RelativeLayout.HeightConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Height,
                                    Factor=0.33}" >
           <StackLayout x:Name="ControlContainer" Orientation="Vertical" VerticalOptions="CenterAndExpand" >
           <Entry x:Name="EmailInput" VerticalOptions="Center" Placeholder="Email" HorizontalOptions="Fill"  />
           <Entry x:Name="PasswordInput" VerticalOptions="Center"  Placeholder="Password" HorizontalOptions="Fill" IsPassword="true" />
        </StackLayout>
      </StackLayout>
    </RelativeLayout>
    <Grid Grid.Row="1" RowSpacing="0" ColumnSpacing="0">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="2*" />
        <ColumnDefinition Width="2*" />
      </Grid.ColumnDefinitions>
      <Button x:Name="LoginButton" Text="Login" BackgroundColor="#FFCF3838" HorizontalOptions="FillAndExpand" Grid.Column="1" Grid.Row="0" BorderWidth="1" BorderColor="White" IsEnabled="{Binding Path=LoginViewModel.IsPageEnabled}" />
      <Button x:Name="RegisterButton" Text="Register" HorizontalOptions="Fill" BackgroundColor="#FFCF3838" Grid.Column="0" Grid.Row="0" BorderWidth="1" BorderColor="White" IsEnabled="{Binding Path=LoginViewModel.IsPageEnabled}" />
    </Grid>

    <StackLayout x:Name="LoadingContainer" BackgroundColor="Black" Opacity="0.7" Orientation="Vertical" IsVisible="{Binding Path=LoginViewModel.IsBusy}"
               RelativeLayout.XConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Width,
                                    Factor=0}"
               RelativeLayout.YConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Height,
                                    Factor=0}"
               RelativeLayout.WidthConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Width,
                                    Factor=0}"
               RelativeLayout.HeightConstraint=
             "{ConstraintExpression Type=RelativeToParent,
                                    Property=Height,
                                    Factor=0}" >
      <StackLayout HeightRequest="70" VerticalOptions="CenterAndExpand">
        <ActivityIndicator IsVisible="{Binding Path=LoginViewModel.IsBusy}"
                         IsRunning="{Binding Path=LoginViewModel.IsBusy}"
                         VerticalOptions="Center"
                         HorizontalOptions="CenterAndExpand"
                         Color="{x:Static common:ColorResources.ActivityIndicatorColor}"
                         RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                                Property=Height,
                                Factor=0.33}"
                         RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
                                Property=Height,
                                Factor=0.33}" />
        <Label Text="Loading ..." Font="12" TextColor="White" VerticalOptions="Center" HorizontalOptions="Center"></Label>
      </StackLayout>
    </StackLayout>
</Grid>

在开始时,StackLayout isVisible="false",内容和按钮都是可见且正常工作的。当isVisible变为true时,StackLayout会用ActivityIndicator覆盖屏幕。如上所述,一切都工作得很好,但我仍然可以单击最初显示的任何按钮,即使我可以看到StackLayout完全覆盖并在屏幕顶部。


很有可能是你的代码问题,因为我已经做过类似的事情,而且它可以正常工作,而不需要选择底层控件。你能否打包一个小例子并发送给其他人帮忙?如果你愿意,你可以通过电子邮件发送,我的详细信息在我的个人资料中。 - Pete
已添加了XAML代码,请告诉我是否需要更多细节。 - Adam
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Pete
1
我的错 - 我在WindowsPhone上运行了这个程序,没有看到你的“android”标签。当我在Android上尝试时 - 是的,我可以看到你的问题,尽管底层控件似乎不能被选择,但它们实际上是可以被选择的。不知道1.3版本将何时发布。 - Pete
感谢 @Pete 的帮助。 - Adam
显示剩余5条评论
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接