TapGestureRecognizer на элементе с отрицательным полем не работает - PullRequest
0 голосов
/ 26 сентября 2019

У меня проблема.Я создал пример проекта, чтобы решить его, но мне не удалось.Я создал кнопку с отрицательным полем, чтобы быть в середине панели навигации.Кран работает только в нижней части.

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="1">
            <Frame HeightRequest="56"
                   Margin="0"
                   Padding="0"
                   BackgroundColor="Yellow" />
            <Grid>
                <Frame WidthRequest="56"
                       HeightRequest="56"
                       Margin="0,-28,0,0"
                       Padding="0"
                       HorizontalOptions="Center"
                       VerticalOptions="Start"
                       BackgroundColor="Blue"
                       CornerRadius="28">
                    <Frame.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding TapCommand}" />
                    </Frame.GestureRecognizers>
                </Frame>
            </Grid>
        </Grid>
    </Grid>
</ContentPage>

Xamarin.Forms: 4.2.0.815419

FAB

1 Ответ

1 голос
/ 26 сентября 2019

Новое редактирование

<?xml version="1.0" encoding="utf-8"?>
<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="helloworld.MainPage">
    <Grid RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <ListView Grid.Row="0" BackgroundColor="Red"/>
        <Frame Grid.Row="1" BackgroundColor="Yellow" Padding="0">
        </Frame>
        <Grid Grid.Row="1" TranslationY="-28">
            <Frame WidthRequest="56"
                    HeightRequest="56"
                    Margin="0"
                    Padding="0"
                    HorizontalOptions="Center"
                    VerticalOptions="Start"
                    BackgroundColor="Blue"
                    CornerRadius="28">
                <Frame.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnTapped" />
                </Frame.GestureRecognizers>
            </Frame> 
        </Grid>
    </Grid>
</ContentPage>

Редактирование

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <RelativeLayout>
        <Grid RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" BackgroundColor="Red" />
            <Grid Grid.Row="1">
                <Frame HeightRequest="56"
                       Padding="0"
                       BackgroundColor="Yellow" />
            </Grid>
        </Grid>
        <Frame WidthRequest="56"
               HeightRequest="56"
               Padding="0"
               HorizontalOptions="Center"
               VerticalOptions="Start"
               BackgroundColor="Blue"
               CornerRadius="28"
               RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                 Property=Width,
                                                                 Factor=0.5,
                                                                 Constant=-28}"
               RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                 Property=Height,
                                                                 Factor=1,
                                                                 Constant=-84}">
            <Frame.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding TapCommand}" />
            </Frame.GestureRecognizers>
        </Frame>
    </RelativeLayout>
</ContentPage>

Старое неправильное решение создано пространство сверхний элемент.

Я удалил поле на кнопке и положил положительное поле на другой элемент.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <ListView Grid.Row="0" BackgroundColor="Red"/>
        <Grid Grid.Row="1">
            <Frame HeightRequest="56"
                   Margin="0,28,0,0"
                   Padding="0"
                   BackgroundColor="Yellow" />
            <Grid>
                <Frame WidthRequest="56"
                       HeightRequest="56"
                       Margin="0"
                       Padding="0"
                       HorizontalOptions="Center"
                       VerticalOptions="Start"
                       BackgroundColor="Blue"
                       CornerRadius="28">
                    <Frame.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding TapCommand}" />
                    </Frame.GestureRecognizers>
                </Frame>
            </Grid>
        </Grid>
    </Grid>
</ContentPage>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...