maui icon indicating copy to clipboard operation
maui copied to clipboard

CollectionView shows no ScrollBar

Open SokoFromNZ opened this issue 3 years ago • 30 comments

Description

When filling a CollectionView with more data than fits on the screen I can scroll CollectionView, but no ScrollBar is shown. Not even if I set the *ScrollBarVisibility to Always or just do this with the VerticalScrollBarVisibility only.

Steps to Reproduce

Create a new .NET MAUI .NET7 App in VS2022 and change those to files to the following (or load my reproduction repository):

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CollectionViewScrollBar.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:collectionViewScrollBar="clr-namespace:CollectionViewScrollBar"
    x:DataType="collectionViewScrollBar:MainPage">

    <CollectionView
        HorizontalScrollBarVisibility="Always"
        ItemsSource="{Binding Rows}"
        VerticalScrollBarVisibility="Always">
        <CollectionView.ItemTemplate>
            <DataTemplate x:DataType="collectionViewScrollBar:Row">
                <Grid RowDefinitions="Auto, Auto">
                    <Label
                        Grid.Row="0"
                        FontAttributes="Bold"
                        Text="{Binding Title}" />
                    <Label
                        Grid.Row="1"
                        FontAttributes="Italic"
                        Text="{Binding Detail}" />
                </Grid>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>

</ContentPage>

MainPage.xaml.cs

using System.Collections.ObjectModel;

namespace CollectionViewScrollBar;

public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();
        BindingContext = this;

        for (var i = 0; i < 50; i++)
        {
            Rows.Add(new Row($"Title-{i}", $"Detail-{i}"));
        }
	}

    public ObservableCollection<Row>  Rows { get; } = new ();
}

public record Row(string Title, string Detail);

image

With a ListView it works: MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CollectionViewScrollBar.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:collectionViewScrollBar="clr-namespace:CollectionViewScrollBar"
    x:DataType="collectionViewScrollBar:MainPage">

    <ListView ItemsSource="{Binding Rows}">
        <ListView.ItemTemplate>
            <DataTemplate x:DataType="collectionViewScrollBar:Row">
                <TextCell Detail="{Binding Detail}" Text="{Binding Title}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</ContentPage>

image

Link to public reproduction project repository

https://github.com/SokoFromNZ/MauiCollectionViewScrollBar

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 11

Did you find any workaround?

No

Relevant log output

No response

SokoFromNZ avatar Nov 15 '22 12:11 SokoFromNZ

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Nov 15 '22 19:11 ghost

@Eilon @jsuarezruiz I was kinda schocked to see this go to the backlog!!

The official MAUI doc (https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/?view=net-maui-7.0) to CollectionView clearly stated to use the CollectionView over all other views! It even says "It aims to provide a more flexible, and performant alternative to ListView." and even "CollectionView automatically utilizes the virtualization provided by the underlying native controls".

But I cannot use any CollectionView in my whole app if the user cannot see if there is more data to scroll. So this should be a Prio-A bug.

I am feeling the pain MAUI puts on developers since day one (also see https://github.com/dotnet/maui/issues/8602). In Mai we had plans to release our product in January, But instead of implementing our business logic, all we do is try to find workarounds for MAUI bugs to get even the simpliest things done... We even cut back from releasing an Android, iOS and Windows version to just Android, but not even the rudimental things in Android work! And now you moving this to the backlog?!

I am frustrated...

SokoFromNZ avatar Nov 16 '22 07:11 SokoFromNZ

@Eilon @jsuarezruiz I was kinda schocked to see this go to the backlog!!

The official MAUI doc (https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/?view=net-maui-7.0) to CollectionView clearly stated to use the CollectionView over all other views! It even says "It aims to provide a more flexible, and performant alternative to ListView." and even "CollectionView automatically utilizes the virtualization provided by the underlying native controls".

But I cannot use any CollectionView in my whole app if the user cannot see if there is more data to scroll. So this should be a Prio-A bug.

I am feeling the pain MAUI puts on developers since day one (also see #8602). In Mai we had plans to release our product in January, But instead of implementing our business logic, all we do is try to find workarounds for MAUI bugs to get even the simpliest things done... We even cut back from releasing an Android, iOS and Windows version to just Android, but not even the rudimental things in Android work! And now you moving this to the backlog?!

I am frustrated...

As a person building an app in MAUI for the first time (first time building an app ever), I assumed that what was written in the documentation was what is actually currently working in MAUI. It's frustrating when the answer is plain as day in the documentation, you follow it, only for it to perform in an unpredictable manner.

I have tried and tried to use the "recommend" CollectionView only for it to never perform as the documentation states. The newest issue I have encountered is not being able to scroll through the CollectioView (thus, how I found this issue!).

Anyway, I too am frustrated and surprised that every issue I encounter (including this) is put on the backlog.

EmberLynn avatar Nov 18 '22 21:11 EmberLynn

スクリーンショット 2022-12-08 0 42 38

Checking this against Xamarin.Forms, Forms doesn't seem to respect the Always Visible setting either for Android, but it does show the bar when scrolling. MAUI does show nothing in main. So this does seem to be a regression.

drasticactions avatar Dec 07 '22 15:12 drasticactions

Any update on this guys? Unbelievable nothing happend here in half a year! I really need a list in MAUI where I can select multiple rows... ListView cannot do this... CollectionView is not usable... Any suggestions?

SokoFromNZ avatar May 11 '23 18:05 SokoFromNZ

Facing this issue on Windows. The scrollbar is only visible when user clicks below the CollectionView. Although I set the ScollBarVisibility to always.

HobDev avatar Jun 07 '23 06:06 HobDev

Here is the work around that I used to resolve this issue.

Create a handler and add the following into the ConnectHandler platformView.VerticalScrollBarEnabled = true; platformView.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideOverlay; platformView.VerticalScrollbarThumbDrawable = AppCompatResources.GetDrawable(this.Context, Resource.Drawable.scrollview_thumb); platformView.ScrollbarFadingEnabled = true;

Create resource file in Android Drawables - scrollview_thumb.xml

mtarros avatar Aug 22 '23 00:08 mtarros

I have same issue, MAUI is REALLY not production ready. CollectionView and CarouselView still has many bug and many of them is 6 months old in backlog.

neonleo avatar Aug 29 '23 07:08 neonleo

I have the same issue with CollcetionView

sergeykonar avatar Sep 15 '23 10:09 sergeykonar

OMG

scriptBoris avatar Dec 11 '23 04:12 scriptBoris

This is still not fixed in MAUI 8

gubhit1s avatar Dec 23 '23 06:12 gubhit1s

Here is the work around that I used to resolve this issue.

Create a handler and add the following into the ConnectHandler platformView.VerticalScrollBarEnabled = true; platformView.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideOverlay; platformView.VerticalScrollbarThumbDrawable = AppCompatResources.GetDrawable(this.Context, Resource.Drawable.scrollview_thumb); platformView.ScrollbarFadingEnabled = true;

Create resource file in Android Drawables - scrollview_thumb.xml

Hello,

Can you give us more details about your workaround, please? I'm very interesting!

Thanks!

zeldomar avatar Dec 27 '23 15:12 zeldomar

We are in 2024 now...

axeldietz avatar Jan 14 '24 09:01 axeldietz

I found a nice workaround. Instead of CollectionView i use DevExpress CollectionView Scrollbar is visible, also performance is better in scrolling

owik100 avatar Jan 14 '24 12:01 owik100

I found a nice workaround. Instead of CollectionView i use DevExpress CollectionView Scrollbar is visible, also performance is better in scrolling

Are you sure that DevExpress.CollectionView offers fast scrolling?

zeldomar avatar Jan 14 '24 12:01 zeldomar

I found a nice workaround. Instead of CollectionView i use DevExpress CollectionView Scrollbar is visible, also performance is better in scrolling

Are you sure that DevExpress.CollectionView offers fast scrolling?

If you means "no lags" then yes, i achieved better performance when scrolling in a view with grid and images.

owik100 avatar Jan 14 '24 14:01 owik100

I found a nice workaround. Instead of CollectionView i use DevExpress CollectionView Scrollbar is visible, also performance is better in scrolling

Are you sure that DevExpress.CollectionView offers fast scrolling?

If you means "no lags" then yes, i achieved better performance when scrolling in a view with grid and images.

No, here is fast scrolling:

Screenshot_2024-01-14-15-22-37-87_40deb401b9ffe8e1df2f1cc5ba480b12

zeldomar avatar Jan 14 '24 14:01 zeldomar

2024 year...

scriptBoris avatar Jan 14 '24 18:01 scriptBoris

Depending on which platforms you aim for... For Windows, this is a crucial property: VerticalOptions="FillAndExpand"

          <CollectionView x:Name="myCollectionView" VerticalOptions="FillAndExpand"
                          RemainingItemsThreshold="5" 
                          RemainingItemsThresholdReached="OnRemainingItemsThresholdReached" 
                          RemainingItemsThresholdReachedCommand="{Binding LoadMoreDataCommand}">
              <CollectionView.ItemTemplate>

FillAndExpand sets the constraints of the CollectionView so that room for the scrollbar(s) can be calculated.

I can understand the generic struggle because it is not mentioned on the Microsoft documentation page, but they actually should have amplified this matter somewhere there. https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/scrolling?view=net-maui-8.0

vvoois avatar Jan 24 '24 08:01 vvoois

I also found the same issue, originally my question was related to this #8888 , but it was closed because they thought it was normal design

shushu789 avatar Feb 21 '24 08:02 shushu789

Still not fixed... It would also be better if we could change the color of the scrollbar...

SlavomirDev avatar Apr 10 '24 15:04 SlavomirDev

What I've discovered is that this won't be fixed as it was done by design. Stacklayout or ContentPage will expand and have an infinite height or the height for all items of the CollectionView. You will need to use a Grid if you want to size to screen and get the scroll.

How to fix:

<ContentPage
    x:Class="Wallet.Views.Transactions.TransactionList"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    
    <Grid ColumnDefinitions="*" RowDefinitions="auto,*">
  <!-- Other code Grid.Row="0".. -->
        <CollectionView
            x:Name="Collection"
            Grid.Row="1">
        </CollectionView>
    </Grid>
</ContentPage>

TalionOak avatar May 07 '24 16:05 TalionOak

Is the CollectionView supposed to scroll just its items or is whole header/footer supposed to scroll too? It is crazy if the header/footer are in the scroll area. In every other framework ever, they are static and just the items scroll.

The above is using a Grid and using a fixed or "*" row height doesn't change anything. So, it is either a bug, or very poor design.

I thought Maui was supposed to be the latest and greatest, but clearly not for Windows apps anyway given how backwards it seems to be. Blazor is far nicer. I lost days trying to convert my WPF to make it work at least as well as in WPF but that just isn't possible. Hell, out of the box, in "light" mode even the Picker and Editor glyphs are white on a white background with no way to fix it AFAICS except to make the background, not white!

Thx1010saascas avatar May 19 '24 03:05 Thx1010saascas

I'm seeing this on a page that only uses grids to layout the controls. I'm migrating a Xamarin.Forms app to .NET MAUI and I had to replace a ListView because I couldn't set the selected item background color. Which is documented as issue #13812

This is a regression from Xamarin.Forms, will it be addressed in .NET 9?

anotherlab avatar Jun 14 '24 13:06 anotherlab

Here is the work around that I used to resolve this issue. Create a handler and add the following into the ConnectHandler platformView.VerticalScrollBarEnabled = true; platformView.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideOverlay; platformView.VerticalScrollbarThumbDrawable = AppCompatResources.GetDrawable(this.Context, Resource.Drawable.scrollview_thumb); platformView.ScrollbarFadingEnabled = true; Create resource file in Android Drawables - scrollview_thumb.xml

Hello,

Can you give us more details about your workaround, please? I'm very interesting!

Thanks!

image image image

Prepare resources first, and Call the below Funtion when program start. You can change colors in scrollview_thumb or something else, just refer to android develop documents. 😭There are so many bugs in maui.

        private void ModifyCollectionView()
        {

            Microsoft.Maui.Controls.Handlers.Items.CollectionViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
            {
#if ANDROID
                handler.PlatformView.VerticalScrollBarEnabled = true;
                handler.PlatformView.ScrollBarStyle = Android.Views.ScrollbarStyles.OutsideOverlay;
                handler.PlatformView.VerticalScrollbarThumbDrawable = AppCompatResources.GetDrawable(Microsoft.Maui.ApplicationModel.Platform.AppContext, Resource.Drawable.scrollview_thumb);
                handler.PlatformView.ScrollbarFadingEnabled = true;
                handler.PlatformView.ScrollBarSize = 50;
#elif IOS || MACCATALYST
           
#elif WINDOWS
          
#endif
            });
        }

OliveInto avatar Aug 09 '24 03:08 OliveInto

Could you, by any chance share your scrollview_thumb file?

Your workaround work well, thanks for that 😁

smardine avatar Aug 22 '24 16:08 smardine

Could you, by any chance share your scrollview_thumb file?

Your workaround work well, thanks for that 😁

I made a simple one, please change the color value to fixed before using it, since the color value in my xml is stored in colors.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
  <corners android:radius="4dp" />
  <solid android:color="@color/customColorScrollbar"/>
</shape>

OliveInto avatar Aug 24 '24 11:08 OliveInto

Super thanks for that 😁

smardine avatar Aug 24 '24 12:08 smardine

Thanks for sharing the thumb file.

I don't have access code anymore, its a shame this is not fixed yet and looking like its not going to be fixed

mtarros avatar Aug 24 '24 21:08 mtarros