Share via

CollectionView selection does not working depending on ItemTemplate

Lloyd Sheen 1,491 Reputation points
2023-01-14T14:58:11.01+00:00

I have a CollectionView which has the following ItemTemplate: (BTW I copy the code and now have no idea what will be shown as I cannot go to the end of this post and put text after the ItemTemplate so another kudo to this forum for its new terrible site).

The definition of the CollectionView is: (And if this post seems screwy it is the site that is causing this.)

As you can see the SelectionMode is Single and I have a SelectedItem and a SelectionChanged event. When I use the ItemTemplate as shown I do not get either the SelectedItem or the event. If I get rid of the Frame I get them but the UI is no good. This has to be a bug since it works sometimes depending on the ItemTemplate.

        <CollectionView ItemsSource="{Binding theDates}" Grid.Row="2"
                        SelectionMode="Single"  
                        SelectedItem="{Binding selectedItem}"
                        SelectionChanged="CollectionView_SelectionChanged">

            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame BorderColor="Gray" CornerRadius="1" BackgroundColor="LightYellow">
                        <VerticalStackLayout>
                            <Label Text="{Binding theDay.Day}" FontSize="10"></Label>
                            <Label Text="{Binding appointMents}" FontSize="10"></Label>
                        </VerticalStackLayout>
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
Developer technologies | .NET | .NET Multi-platform App UI

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.