[英]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.