DottorPagliaccius / Xamarin-Custom-Controls

in progress
MIT License
96 stars 34 forks source link

Nested RepeaterView SelectedItemCommand Not Working #27

Closed bish25 closed 6 years ago

bish25 commented 6 years ago

i have a RepeaterView that then has a child ReapterView. The Selected Item works for the parent, however not for the child selected item command. `

`
DottorPagliaccius commented 6 years ago

Hi @bish25, I suppose this is an InputTransparent-issue; try adding InputTrasparent=true on parent repeater. Alternatively, you can try adding the command to a TapGesture attached to inner stacklayout. Let me know.

P.S.: there's no need for the DataTemplate to be inside a ViewCell

bish25 commented 6 years ago

hi @DottorPagliaccius thanks for the reply, i have tried setting the inputTransparent=true and still not luck, i will try the tap gesture and see if that works.

also regarding your ps, if i remove the DataTemplate it gives out errors

Thanks again

bish25 commented 6 years ago

i have added the tap gesture but still no luck, i've even tried in the parent repeater but the gesture doesn't work.

<repeater:RepeaterView x:Name="MainRepeater2" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver"
                                        ItemsSource="{Binding Items}">
                                        <repeater:RepeaterView.ItemTemplate>
                                            <DataTemplate>
                                                <ViewCell>
                                                    <StackLayout Orientation="Horizontal">
                                                        <StackLayout.GestureRecognizers>
                                                            <TapGestureRecognizer Command="{Binding RSSFeedSelectedCommand}" NumberOfTapsRequired="1"/>
                                                            </StackLayout.GestureRecognizers>
                                                        <Image Source="{Binding Image.Url}"></Image>
                                                        <StackLayout Orientation="Vertical">
                                                        <Label Text="{Binding Title}"  TextColor="Black" />
                                                        <Label Text="{Binding Description}" TextColor="Black" FontSize="12" />
                                                        </StackLayout>
                                                    </StackLayout>
                                                </ViewCell>
                                            </DataTemplate>
                                        </repeater:RepeaterView.ItemTemplate>
                                    </repeater:RepeaterView>
DottorPagliaccius commented 6 years ago

I said you can safely remove the container, not the DataTemplate one ;)

As soon as I have some time I will try to reproduce the issue, I'll let you know.

bish25 commented 6 years ago

Okay that would be perfect, i have other things i can be working on in the mean while, but can see this appearing more than one place in the app. :)

DottorPagliaccius commented 6 years ago

Got it, it was obvious: when you're referencing objects in the inner Repeater, you're referencing the properties of the current element of the parent Repeater ItemSource; so, if "RSSFeedSelectedCommand" is not a field of the Items object (but it's, as I suppose, a field from the ViewModel), you should reference it this way:

SelectedItemCommand="{Binding Source={x:Reference PageName}, Path=BindingContext. RSSFeedSelectedCommand}"

and you have to name the page:

<ContentPage x:Name="PageName" etc

bish25 commented 6 years ago

damn that was obvious, Thanks for your help as it now works 👍 PS very good control!

DottorPagliaccius commented 6 years ago

Thank you very much, glad to help ;)

csharpq commented 6 years ago

Hi @bish25

Would you mind if I ask you how did you handle the binding of this nested repeater view in ViewModel?

I am working now on this but I can't make it work.

the first binding works fine like below, it shows the expected data in my listing <repeater:RepeaterView x:Name="MainRepeater" EmptyText="" ShowSeparator="true" SeparatorHeight="25" SeparatorColor="Silver" ItemsSource="{Binding Feeds}" >

but the second binding doesn't show my data

<repeater:RepeaterView x:Name="MainRepeater" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver"
                                    ItemsSource="{Binding Items}">

I think there is something wrong on my ViewModel. Hope you can help me on this :)

Many thanks.

DottorPagliaccius commented 6 years ago

Hi @maryjoyquijano, it should word. Stupid question: is "Items" collection a child property of a "Feeds" single element? Inner and parent repeater don't share the same x:Name as in the code you posted, right?

P.S.: please next time open another ticket instead of answering to an old, closed one ;)