Xaml 相对布局中元素上的事件未触发

Xaml 相对布局中元素上的事件未触发,xaml,xamarin,button,xamarin.forms,Xaml,Xamarin,Button,Xamarin.forms,我使用的是Xamarin表单,相对布局中的元素上的事件没有触发。我也试着在代码隐藏中注册它们,但仍然没有开火。我对它有-250的限制,因为按钮显示在屏幕底部,这是我唯一可以向上移动它们的方法。 这是我的xaml: <StackLayout Orientation="Vertical"> <RelativeLayout> <Grid Margin="0,0,10,0" x:Name="grid"

我使用的是Xamarin表单,相对布局中的元素上的事件没有触发。我也试着在代码隐藏中注册它们,但仍然没有开火。我对它有-250的限制,因为按钮显示在屏幕底部,这是我唯一可以向上移动它们的方法。 这是我的xaml:

 <StackLayout Orientation="Vertical">
    <RelativeLayout>
        <Grid Margin="0,0,10,0"
              x:Name="grid"
              RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=10}" 
              RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=0}" 
              >


        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*" />
            <ColumnDefinition Width="50*" />
        </Grid.ColumnDefinitions>

        <Label Grid.Column="0"
               Grid.Row="0"
                Text="IP Address"
               Margin="10,10,0,0"
               HorizontalOptions="StartAndExpand"/>
        <Entry Grid.Column="1"  
               Grid.Row="0"
            x:Name="IPAddress"
            Placeholder="IP"
               WidthRequest="200"

                Margin="0,0,10,0"
            HorizontalOptions="EndAndExpand"/>
        <Label Grid.Column="0"
               Grid.Row="1"
                Text="Port"
               Margin="10,10,0,0"
               MinimumWidthRequest="100"
               HorizontalOptions="Start"/>
        <Entry Grid.Column="1"  
               Grid.Row="1"
            x:Name="Port"
               Margin="0,0,10,0"
            Placeholder="Port"
                WidthRequest="200"
            HorizontalOptions="End"/>
        <Label Grid.Column="0"
               Grid.Row="2"
               Margin="10,10,0,0"
                Text="User Name"
               MinimumWidthRequest="100"
               HorizontalOptions="Start"/>
        <Entry Grid.Column="1"  
               Grid.Row="2"
            x:Name="UserName"
               Margin="0,0,10,0"
                WidthRequest="200"
            Placeholder="User Name"
            HorizontalOptions="End"/>
        <Label Grid.Column="0"
               Grid.Row="3"
               Margin="10,10,0,0"
                Text="Password"
               MinimumWidthRequest="100"
               HorizontalOptions="Start"/>
        <Entry Grid.Column="1"  
               Grid.Row="3"
            x:Name="Password"
               IsPassword="True"
               Margin="0,0,10,0"
                WidthRequest="200"
            Placeholder="Password"
            HorizontalOptions="End"/>

        </Grid>

    </RelativeLayout>
    <RelativeLayout
        IsEnabled="True">
        <Button x:Name="SaveBtn"
                IsEnabled="True"
                WidthRequest="100"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=-250}"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=30}"
                Clicked="SaveBtn_Clicked"
                BorderColor="Gray"
                Text="Save"></Button>
        <Button x:Name="ClearFavorites"
                IsEnabled="True"
                WidthRequest="120"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=-250}" 
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=20}"
                Clicked="ClearFavorites_Clicked"
                BorderColor="Gray"
                Text="Clear Favorites"></Button>
    </RelativeLayout>
</StackLayout>

在讨论聊天后,这似乎有效

<StackLayout Orientation="Vertical"> 
<RelativeLayout> 
<Grid Margin="0,0,10,0" 
x:Name="grid" 
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=10}" 
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=0}" 
> 


<Grid.RowDefinitions> 
<RowDefinition Height="Auto"/> 
</Grid.RowDefinitions> 
<Grid.ColumnDefinitions> 
<ColumnDefinition Width="50*" /> 
<ColumnDefinition Width="50*" /> 
</Grid.ColumnDefinitions> 

<Label Grid.Column="0" 
Grid.Row="0" 
Text="IP Address" 
Margin="10,10,0,0" 
HorizontalOptions="StartAndExpand"/> 
<Entry Grid.Column="1" 
Grid.Row="0" 
x:Name="IPAddress" 
Placeholder="IP" 
WidthRequest="200" 

Margin="0,0,10,0" 
HorizontalOptions="EndAndExpand"/> 
<Label Grid.Column="0" 
Grid.Row="1" 
Text="Port" 
Margin="10,10,0,0" 
MinimumWidthRequest="100" 
HorizontalOptions="Start"/> 
<Entry Grid.Column="1" 
Grid.Row="1" 
x:Name="Port" 
Margin="0,0,10,0" 
Placeholder="Port" 
WidthRequest="200" 
HorizontalOptions="End"/> 
<Label Grid.Column="0" 
Grid.Row="2" 
Margin="10,10,0,0" 
Text="User Name" 
MinimumWidthRequest="100" 
HorizontalOptions="Start"/> 
<Entry Grid.Column="1" 
Grid.Row="2" 
x:Name="UserName" 
Margin="0,0,10,0" 
WidthRequest="200" 
Placeholder="User Name" 
HorizontalOptions="End"/> 
<Label Grid.Column="0" 
Grid.Row="3" 
Margin="10,10,0,0" 
Text="Password" 
MinimumWidthRequest="100" 
HorizontalOptions="Start"/> 
<Entry Grid.Column="1" 
Grid.Row="3" 
x:Name="Password" 
IsPassword="True" 
Margin="0,0,10,0" 
WidthRequest="200" 
Placeholder="Password" 
HorizontalOptions="End"/> 

</Grid> 

</RelativeLayout> 
<RelativeLayout 
IsEnabled="True"> 
<Button x:Name="SaveBtn" 
IsEnabled="True" 
WidthRequest="100" 
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=50}" 
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=30}" 
Clicked="SaveBtn_Clicked" 
BorderColor="Gray" 
Text="Save"></Button> 
<Button x:Name="ClearFavorites" 
IsEnabled="True" 
WidthRequest="120" 
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=50}" 
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=20}" 
Clicked="ClearFavorites_Clicked" 
BorderColor="Gray" 
Text="Clear Favorites"></Button> 
</RelativeLayout> 
</StackLayout>


单击SaveBtn\u定义显示代码您的约束将按钮移出屏幕。当我将它们设置为“查看”按钮时,我会同时看到两个单击事件您使用的是什么设备?我正在测试5s和6,按钮在屏幕上。安卓模拟器5#marsmallow。Y常量=-250可以在屏幕上显示多少?按钮显示在我屏幕的最底部。添加-250约束是我可以垂直移动它们的唯一方法。