Xamarin 表单,框架内的按钮未触发事件

Xamarin forms, buttons inside frame are not firing an event

我有一个表单,里面有一个框架和 3 个按钮。

点击事件没有触发这些按钮中的任何一个。

我在框架外放了一个按钮,它可以点击。

表格来自本页的示例 https://askxammy.com/replicating-user-profile-ui-in-xamarin-forms/.

我问了作者,但她没有回应。 这是代码。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         x:Class="UserProfileUISample.MainPage">

    <Grid BackgroundColor="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions>

     <!-- 1. Profile picture-->   
     <Image Grid.Row="0" Source="KattyWhite" VerticalOptions="Start" /> 

     <!-- 2. Contact informaqtion frame-->   
     <StackLayout Grid.Row="0" BackgroundColor="White" VerticalOptions="End">
        <Frame CornerRadius="40" Style="{StaticResource stlMainFrame}" >
            <!-- Blocks: 3 and 4 -->
            <Grid Padding="25,10,25,0" RowSpacing="0"> 
               <Grid.ColumnDefinitions>
                   <ColumnDefinition Width="*"/>
                   <ColumnDefinition Width="*"/>
                   <ColumnDefinition Width="*"/>
               </Grid.ColumnDefinitions> 
               <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/> 
               </Grid.RowDefinitions>
                  <!-- 3. Phone & message buttons-->
                <Button x:Name="btn1" Grid.Row="0" Grid.Column="1" Style="{StaticResource stlContactBtn}" HorizontalOptions="End"   ImageSource="Phone" Clicked="OnClicked"/>
                 <Button x:Name="btn2" Grid.Row="0" Grid.Column="2" Style="{StaticResource stlContactBtn}" HorizontalOptions="Start" ImageSource="Correo" Clicked="Button_Clicked_1"/>
                 <!-- 4. Contact information-->
                 <Label x:Name="lblName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Text="Katty White" FontAttributes="Bold" FontSize="20"/>
                 <Label x:Name="lblCode" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Text="New York" TextColor="#a5a2a2" FontSize="16"/>
                 <!--<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Padding="0,10,0,0" FontSize="16">
                   <Label.FormattedText>
                        <FormattedString>
                            <Span Text="Email: " FontAttributes="Bold" />
                            <Span Text=" kattywhite@hotmail.com"  /> 
                        </FormattedString>
                    </Label.FormattedText>
                 </Label>-->
                <!--4. Contact information: Board inforation-->
                <Label Grid.Row="3" Grid.Column="0" Text="Λαχεία" Style="{StaticResource stlBoardTitle}" />
                <Label x:Name="lblLaxeia" Grid.Row="4" Grid.Column="0" Text="678" Style="{StaticResource stlBoardDesc}"/>

                <Label Grid.Row="3" Grid.Column="1" Text="Γεμίσματα" Style="{StaticResource stlBoardTitle}"/>
                <Label x:Name="lblGemismata" Grid.Row="4" Grid.Column="1" Text="340" Style="{StaticResource stlBoardDesc}"/>

                <Label Grid.Row="3" Grid.Column="2" Text="Κληρώσεις" Style="{StaticResource stlBoardTitle}"/>
                <Label x:Name="lblKliroseis" Grid.Row="4" Grid.Column="2" Text="67k" Style="{StaticResource stlBoardDesc}"/>
                <!--4. Contact information: Follow button-->
                <Button x:Name="btn3" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" TextColor="White" BackgroundColor="#2193f3" Text="Αναλυτικά" Margin="0,20,0,2" FontAttributes="Bold" FontSize="17" HeightRequest="45"/>
            </Grid> 
         </Frame>
        <Button x:Name="btn22" Grid.Row="6" Grid.Column="2" Style="{StaticResource stlContactBtn}" HorizontalOptions="Start" ImageSource="Correo" Clicked="Button_Clicked_1"/>

    </StackLayout>
   
</Grid> 

你能帮帮我吗? 谢谢

当你给按钮设置TranslationY="-50" 属性时,它会使按钮超出Grid的边界,所以它不会响应点击事件。

有关于 github https://github.com/xamarin/Xamarin.Forms/issues/6760 的报告。

我建议您将这些按钮或标签直接添加到网格中,并使用 absolute-layout, relative-layout 或其他布局来固定它们的位置。