Access a visual element inside a collectionview in .net maui

295 Views Asked by At

I have this CollectionView. Inside are ellipses. I can't access them from code-behind. They are there, I can see them through the debugger. They are like (CollectionView.base.base.base.base.base.base.base.Children) but for everything I tried I can't get them. And I think there is no VisualTreeHelper class in .net maui unlike wpf

<CollectionView ItemsSource="{Binding SolutionColors}" 
            SelectionMode="None"    
            x:Name="solutionColorsCollectionView">
    <CollectionView.ItemsLayout>
        <GridItemsLayout Orientation="Vertical" Span="{Binding NumberOfCircles}"
                 HorizontalItemSpacing="10"
                 VerticalItemSpacing="10" />
    </CollectionView.ItemsLayout>
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <Ellipse Fill="{Binding Color}" WidthRequest="60" HeightRequest="60">
                <Ellipse.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type local:CircleColorsViewModel}}, Path=SetSolutionColorCommand}"
                          CommandParameter="{Binding Index}" />
                </Ellipse.GestureRecognizers>
            </Ellipse>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>
                

Thank you so much.

1

There are 1 best solutions below

4
Nevin Sever On

solutionColorsCollectionView.GetVisualTreeDescendants() did it.