这可能是一个简单的解决方案,但是由于某些原因,我无法在线找到该解决方案。
我有两种看法。一个视图是网格,另一个视图是按钮。网格视图显示不同的视图(框视图,标签等。)
但是在下面是按钮视图。但是此视图未包含在“网格视图”中。由于某些原因,我无法将其放入“网格视图”中。我只是想知道是否有可能在不移动视图的情况下单击它,或者即使它之上有视图?
这是它的样子:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PlayUIArea.NotificationConfirmView">
<ContentView.Content>
<Grid BackgroundColor="Blue">
<BoxView
WidthRequest="100"
VerticalOptions="Fill"
HorizontalOptions="Start"
BackgroundColor="Black" />
<Button Text="Confirm"
OnClick="Button_Click"
VerticalOptions="Start"
HorizontalOptions="Center" />
<Grid BackgroundColor="Red" Margin="100,0,0,0" Padding="-100,0,0,0">
<Label Text="Label Here"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Grid>
</Grid>
</ContentView.Content>
</ContentView>
反正有没有可以点击的选项?
答案 0 :(得分:0)
同意@ G.Mich,您应该将所有元素放在一个布局中。例如,您可以将它们放在StackLayout
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Button Onclick="Button_Clicked" /> <!-- This isn't clickable -->
<Grid>
your code here
</Grid>
</StackLayout>
</ContentPage.Content>
答案 1 :(得分:0)
我来晚了,但我想我找到了解决方案。
<Grid>
<WebView Grid.Row ="1" Source="[insert random embedded youtube source]"/>
<RelativeLayout Grid.Row ="1" InputTransparent="True" CascadeInputTransparent="False">
<Button CornerRadius="0" Command="{Binding GoToVideoFullscreen}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.8}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.9}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=Constant, Constant=17}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=17}"/>
</RelativeLayout>
</Grid>
我遇到了类似的问题,我想将 WebView 与自定义按钮重叠。但是我用来放置按钮的 RelativeLayout 占用了所有输入,无法再使用 WebView。
所以我在 InputTransparent="True"
中添加了 CascadeInputTransparent="False"
和 RelativeLayout
。 InputTransparent="True"
使其对输入不可见,CascadeInputTransparent="False"
防止 InputTransparent
值继承到子项(在本例中为我的按钮)。
文档:
答案 2 :(得分:-4)
将button
放在Grid
上方,方法是将其放在XAML中的网格之后
<ContentPage.Content>
<Grid>
My code here
</Grid>
<Button Onclick="Button_Clicked" /> <!-- This isn't clickable -->
</ContentPage.Content>