0

In one of my pages of my .NET MAUI 8 application, I provide a search functionality. At the top of the ContentPage, there are a few controls to set search parameters, followed by a button to do the actual search. At the bottom of the content page is a CollectionView with all search results.

The found items are grouped by date. This means that each search result displayed in the CollectionView has a title and their own collection of items. This leads to nested CollectionViews.

I redacted the code for the sake of simplicity. The content page looks roughly like this:

<!-- Main content -->
<ScrollView x:Name="ScrollView"
            Grid.Row="2">
    <Grid Margin="10,10,10,10"
          RowSpacing="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- Search options + Search button are here (row 0 to 5) -->

        <!-- Search results -->
        <Label Grid.Row="6"
               Text="{Binding Path=SearchResultsCaption}"
               TextColor="{StaticResource Key=AccentColor}"
               TextTransform="Uppercase"
               FontSize="16"
               Margin="0,13,0,0" />

        <CollectionView Grid.Row="7"
                        x:Name="SearchResultsCollectionView"
                        ItemsSource="{Binding Path=SearchResultGroups}" 
                        ItemsLayout="VerticalGrid">
            <CollectionView.ItemTemplate>
                <DataTemplate x:DataType="redacted">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <controls:SectionHeader Grid.Row="0"
                                                BindingContext="{Binding Path=Title}"
                                                Margin="0,0,0,5" />

                        <CollectionView Grid.Row="1"
                                        ItemsSource="{Binding Path=redacted}"
                                        ItemsLayout="VerticalGrid">
                            <CollectionView.ItemTemplate>
                                <DataTemplate x:DataType="redacted">
                                    <Border StrokeThickness="1"
                                            Stroke="{StaticResource Key=BorderColor}"
                                            Background="White"
                                            Margin="0,0,0,5">
                                        <!-- nice looking search result -->
                                    </Border>
                                </DataTemplate>
                            </CollectionView.ItemTemplate>
                        </CollectionView>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </Grid>
</ScrollView>

The problem now occurs on my test iOS device, if I place my finger on the first search result and scroll. I do not scroll the entire page, but only the search results in the first CollectionView (which contains all search results).

What I want to achieve is that no matter where on the page I start scrolling everything is scrolled. I want a behavior as if I was using WPF and had ItemControls without scrolling options or as if the CollectionView behaved just liked repeated grids listing all the content vertically.

How can I achieve this in .NET MAUI? I did not find native alternatives to CollectionViews or properties in the CollectionView that disabled nested scrolling.

5
  • 2
    Don't nest Scrollable views into each other
    – FreakyAli
    Commented Apr 9 at 7:11
  • I know that and I wrote what I need, but that I don't know how to do it. I would need a non-scrollable version of CollectionView. In WPF you could use ItemsControl, but what can I use for .NET MAUI?
    – BeRo
    Commented Apr 9 at 12:03
  • Like FreakyAli correctly pointed out, you shouldn't nest scrollable views, but you are nesting three. You'll have to rethink your design. Please show what it should look like, then someone may be able to provide a different approach. CollectionViews support grouping, so that you don't have to nest CollectionViews. If you still need to nest something, maybe use a VerticalStackLayout in combination with a BindableLayout.
    – Julian
    Commented Apr 9 at 13:18
  • In addition to the sample code in BindableLayout doc that Julian linked, see BindableLayout Examples. As Julian said, use BindableLayout with Vertical/HorizontalStackLayout; depending on needed Orientation. Commented Apr 11 at 17:55
  • Do you need to select an item (a row)? IIRC, do this in a BindableLayout by making each item a Button. If you need selection of items, and have trouble getting buttons to do what you need, start a new question with code as far as you can get it. Commented Apr 11 at 17:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.