【发布时间】:2014-12-20 00:38:31
【问题描述】:
我在 Xamarin Forms 中有一个页面,最后我有一个 StackLayout 覆盖整个屏幕,只有在我调用它时才可见。
StackLayout 正确显示,ActivityIndicator 也正确显示。但是,我仍然可以单击技术上应该位于堆栈布局下方的任何控件。
这是预期的行为吗?在 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 完全覆盖并位于屏幕顶部。
【问题讨论】:
-
这可能取决于您的代码,因为我已经完成了类似的操作,并且工作正常,没有可选择的底层控件。你能打包一个小例子并发送给其他人吗?如果您愿意,可以通过电子邮件发送,我的详细信息在我的个人资料中。
-
添加了上面的 XAML,如果您需要更多详细信息,请告诉我。
-
当我取出绑定时,它似乎可以工作(并将它们替换为 True 值),但是活动指示器并没有覆盖整个页面。您能否通过电子邮件发送解决方案以便我运行它?或者重新创建另一个小示例来说明这一点,以便我可以进一步提供帮助?
-
我更新了 XAML 以大致显示整个 XAML 是什么。如果您需要更多信息,我可以通过该项目向您发送。如果这有什么不同,我正在使用 MVVM Light v5。
-
我的错 - 我在 WindowsPhone 上运行它时没有看到你的“android”标签。当我在 Android 上尝试时 - 是的,尽管底层控件的外观不可选择,但我可以准确地看到您的问题,它们是。不知道什么时候会发布 1.3 版。
标签: c# android xamarin.forms