简体   繁体   English

StackLayout 位于控件之上,但允许在.Net MAUI 中点击按钮和条目

[英]StackLayout stays above controls, but allows tap on buttons and entries in .Net MAUI

I have a StackLayout inside an AbsoluteLayout with some entries and a button, and the StackLayout has the LayoutBounds equal to "0,0,1,1" and the LayoutFlags equal to "All".我在 AbsoluteLayout 中有一个 StackLayout,其中包含一些条目和一个按钮,并且 StackLayout 的 LayoutBounds 等于“0,0,1,1”,LayoutFlags 等于“All”。

When I tap on the button, I show a Grid that has the same AbsoluteLayout properties described above, so that this Grid positions itself above the previous StackLayout, hiding all controls.当我点击按钮时,我会显示一个具有上述相同 AbsoluteLayout 属性的 Grid,因此该 Grid 将自身定位在先前的 StackLayout 之上,隐藏所有控件。 This Grid has a BoxView with a Gray color with some opacity, and an ActivityIndicator running.这个 Grid 有一个带有灰色的 BoxView 和一些不透明度,以及一个正在运行的 ActivityIndicator。

Everything works as expected, except the fact that I still can tap on the entries (showing the virtual keyboard) and the button.一切都按预期工作,除了我仍然可以点击条目(显示虚拟键盘)和按钮这一事实。

I know that this Grid is above the StackLayout with the controls, but why can I still tap on them?我知道这个 Grid 是在 StackLayout 上面的控件,但是为什么我仍然可以点击它们呢? I have the same solution in Xamarin Forms, and it works as expected, the controls have their events inhibited, since they are in a layer beneath.我在 Xamarin Forms 中有相同的解决方案,它按预期工作,控件的事件被抑制,因为它们位于下面的层中。

Here is some sample code.这是一些示例代码。 For testing purposes, the Grid is already visible, but the intent is only making it visible after the tap on the button.出于测试目的,网格已经可见,但意图只是在点击按钮后使其可见。

<?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>

As you can see, the entries and the button have their background color red with some transparency, meaning that the grid is above the stacklayout, but I still can tap on the entries (and the button) as the screenshots show.如您所见,条目和按钮的背景颜色为红色,具有一定的透明度,这意味着网格位于堆栈布局上方,但我仍然可以点击条目(和按钮),如屏幕截图所示。

Before tapping on the entry在点击条目之前

After tapping the entry点击进入后

Yes, it is the case as you said.是的,正如你所说的那样。 As a test, I replaced VerticalStackLayout with StackLayout and changed the property of BoxView from BackgroundColor="Red" to BackgroundColor="Transparent" .作为测试,我将VerticalStackLayout替换为StackLayout并将BoxView的属性从BackgroundColor="Red"更改为BackgroundColor="Transparent"

Then I tested on xamarin forms, there was no such problem.然后我在xamarin forms上测试,没有这个问题。 This should be an issue in maui.这应该是毛伊岛的一个问题。

And I have created a new issue about this problem, you can follow it up here: https://github.com/dotnet/maui/issues/9514 .我创建了一个关于这个问题的新问题,你可以在这里跟进: https://github.com/dotnet/maui/issues/9514

Thanks for your feedback.感谢您的反馈意见。 Have a nice day.祝你今天过得愉快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM