AndreiMisiukevich / CardView

CardsView | CarouselView | CoverflowView | CubeView for Xamarin.Forms
MIT License
710 stars 114 forks source link

Обработка нажатия на вложенный элемент. #389

Closed IhorVolodko closed 3 years ago

IhorVolodko commented 3 years ago

Добрый день. Столкнулся с проблемой обработки нажатия на вложенный элемент. Он содержит 2 кнопки с разными командами. На Android все работает замечательно, на iOS Tap перехватывается.

AndreiMisiukevich commented 3 years ago

Привет, можешь пожалуйста создать тестовый проект? Не совсем понимаю, что имеется в виду. Спасибо

AndreiMisiukevich commented 3 years ago
<cards:CarouselView ItemsSource="{Binding Items}">
    <cards:CarouselView.ItemTemplate>
        <StackLayout>
            // Две кнопки здесь?
        </StackLayout>
    </cards:CarouselView.ItemTemplate>
</cards:CarouselView>

Как это выглядит в коде, можешь скинуть, пожалуйста? Лучше создай отдельный небольшой проектик)

Спасибо

IhorVolodko commented 3 years ago

Здесь в ресурсах TemplateSelector, и CarouselView на странице. А так же прикрепил сам DataTemplate в виде ContentView (это последний 4й элемент в ItemSource)

 <selectors:StartViewTemplateSelector.StartPageContentTemplate_4>
                    <DataTemplate>
                        <controls:StartPageContent_4/>
                    </DataTemplate>
                </selectors:StartViewTemplateSelector.StartPageContentTemplate_4>

carouselView:CarouselView Grid.Row="0"
                                    x:Name="startPageCarouselView"
                                    HorizontalOptions="FillAndExpand"
                                    IsUserInteractionEnabled="True"
                                    IsTabStop="True"
                                    IsCyclical="False"
                                    IsVisible="False"
                                    IndicatorView="{x:Reference carouselIndicator}"
                                    ItemsSource="{Binding Contents}"
                                    ItemTemplate="{x:StaticResource starViewTemplateSelector}">

<?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="MyAPP.Controls.StartPageCarouselItems.StartPageContent_4"
             xmlns:controls="clr-namespace:MyAPP.Controls">

    <ContentView.Resources>
        <ResourceDictionary>

            <!--STYLES-->
            <Style x:Key="buttonFrameStyle" TargetType="Frame">
                <Setter Property="VerticalOptions" Value="FillAndExpand"/>
                <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
                <Setter Property="CornerRadius" Value="15"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="Margin" Value="0"/>
                <Setter Property="HasShadow" Value="False"/>
            </Style>
            <Style x:Key="clickableContentViewStyle" TargetType="controls:ClickableContentView">
                <Setter Property="HeightRequest" Value="56"/>
                <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
                <Setter Property="Margin" Value="20,0"/>
                <Setter Property="Padding" Value="0"/>
            </Style>
            <Style x:Key="buttonTextStyle" TargetType="Label">
                <Setter Property="HorizontalOptions" Value="Center"/>
                <Setter Property="VerticalOptions" Value="Center"/>
                <Setter Property="FontSize" Value="20"/>
                <Setter Property="VerticalTextAlignment" Value="Center"/>
                <Setter Property="TextTransform" Value="Uppercase"/>
            </Style>
            <Style x:Key="infoLabel" TargetType="Label" >
                <Setter Property="HorizontalTextAlignment" Value="Center"/>
                <Setter Property="FontSize" Value="35"/>
                <Setter Property="TextColor" Value="#0161a0"/>
                <Setter Property="TextTransform" Value="Uppercase"/>
            </Style>

        </ResourceDictionary>
    </ContentView.Resources>

    <Grid RowDefinitions="0.4*, 0.6*"
          VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand">

        <StackLayout Grid.Row="0"
                     HorizontalOptions="CenterAndExpand"
                     VerticalOptions="End">

            <Label Text="Hello"
                   Style="{x:DynamicResource tstyle_i2}"
                   HorizontalTextAlignment="Center"
                   TextTransform="Uppercase"/>

        </StackLayout>

        <StackLayout Grid.Row="1"
                     HorizontalOptions="FillAndExpand"
                     VerticalOptions="Center"
                     Spacing="20"
                     Margin="0,20">

           <Button Text="Button1"
                          HeightRequest="30"
                         WidthRequest="100"
                         BackgroundColor="Red"/>

           <Button Text="Button2"
                         HeightRequest="30"
                         WidthRequest="100"
                         BackgroundColor="Red"/>

        </StackLayout>

    </Grid>

</ContentView>
AndreiMisiukevich commented 3 years ago

@IhorVolodko Окей, я вижу что у кнопок нет ни команд, ни обработчиков эвентов кликов. В таком случае, конечно, это не будет работать.

Именно поэтому я прошу создать отдельный Проект, который я смогу запустить и посмотреть. Убери, пожалуйста, все лишнее, оставь только важные детали и приаттчь сюда zip архив

IhorVolodko commented 3 years ago

Работает. Если нацепить GesrureRecognizer. не работает сама анимация нажатия кнопки на iOS

AndreiMisiukevich commented 3 years ago

не совсем понял, а просто Button Command или Clicked не работает?

AndreiMisiukevich commented 3 years ago

Можно тогда анимацию добавить с помощью TouchEffect из Xamarin Community Toolkit

https://andrei-misiukevich.medium.com/touch-effect-xamarin-forms-xamarin-community-toolkit-91fb6691f99e

IhorVolodko commented 3 years ago

Я не заметил отсутствие рендера и а кастомный контрол, проблема оказалась в этом. Дополнительно сбила отсутсвие анимации на кнопке

ср, 26 мая 2021 г. в 20:38, Andrei @.***>:

Можно тогда анимацию добавить с помощью TouchEffect из Xamarin Community Toolkit

https://andrei-misiukevich.medium.com/touch-effect-xamarin-forms-xamarin-community-toolkit-91fb6691f99e

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/AndreiMisiukevich/CardView/issues/389#issuecomment-848980844, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUBPCUDJGODEUIQP63VQL2LTPUWYHANCNFSM45PO7GUA .