[英]StackLayout stays above controls, but allows tap on buttons and entries in .Net MAUI
我在 AbsoluteLayout 中有一个 StackLayout,其中包含一些条目和一个按钮,并且 StackLayout 的 LayoutBounds 等于“0,0,1,1”,LayoutFlags 等于“All”。
当我点击按钮时,我会显示一个具有上述相同 AbsoluteLayout 属性的 Grid,因此该 Grid 将自身定位在先前的 StackLayout 之上,隐藏所有控件。 这个 Grid 有一个带有灰色的 BoxView 和一些不透明度,以及一个正在运行的 ActivityIndicator。
一切都按预期工作,除了我仍然可以点击条目(显示虚拟键盘)和按钮这一事实。
我知道这个 Grid 是在 StackLayout 上面的控件,但是为什么我仍然可以点击它们呢? 我在 Xamarin Forms 中有相同的解决方案,它按预期工作,控件的事件被抑制,因为它们位于下面的层中。
这是一些示例代码。 出于测试目的,网格已经可见,但意图只是在点击按钮后使其可见。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PdC.Views.SamplePage"
Title="SamplePage">
<AbsoluteLayout>
<VerticalStackLayout
BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Padding="0,50,0,0"
Spacing="50">
<Entry
WidthRequest="200"
BackgroundColor="Yellow"
TextColor="Black"
Text="sample text on first entry" />
<Entry
WidthRequest="200"
TextColor="Black"
BackgroundColor="Yellow"
Text="sample text on second entry" />
<Button
Text="tap on me"
WidthRequest="200" />
</VerticalStackLayout>
<Grid
IsVisible="True"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<BoxView
ZIndex="9"
Grid.RowSpan="2"
BackgroundColor="Red"
VerticalOptions="FillAndExpand"
Opacity="0.5" />
<Frame
BackgroundColor="White"
Grid.Row="1">
<VerticalStackLayout
VerticalOptions="FillAndExpand">
<ActivityIndicator
IsRunning="True"
HorizontalOptions="Center"
Color="Red"/>
<Label
TextColor="Black"
Text="Please wait ..."
HorizontalOptions="Center"/>
</VerticalStackLayout>
</Frame>
</Grid>
</AbsoluteLayout>
</ContentPage>
如您所见,条目和按钮的背景颜色为红色,具有一定的透明度,这意味着网格位于堆栈布局上方,但我仍然可以点击条目(和按钮),如屏幕截图所示。
是的,正如你所说的那样。 作为测试,我将VerticalStackLayout
替换为StackLayout
并将BoxView
的属性从BackgroundColor="Red"
更改为BackgroundColor="Transparent"
。
然后我在xamarin forms上测试,没有这个问题。 这应该是毛伊岛的一个问题。
我创建了一个关于这个问题的新问题,你可以在这里跟进: https://github.com/dotnet/maui/issues/9514 。
感谢您的反馈意见。 祝你今天过得愉快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.