Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Content of Grid placed inside ScrollView is partially visible #17870

Closed
jns300 opened this issue Oct 6, 2023 · 3 comments
Closed
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 t/bug Something isn't working

Comments

@jns300
Copy link

jns300 commented Oct 6, 2023

Description

The linked code creates view with the following aggregation order: Frame, Grid, ScrollView, AdaptableGrid.
Inside an object of the class AdaptableGrid a matrix of 10 columns and 10 rows is created. Inside each cell objects of the class ContentViewItem are placed.
The AdaptableGrid class sets the same size to its children in the method OnSizeAllocated. At the end of this method, the InvalidateMeasure method is called using Dispatcher: Dispatcher.Dispatch(InvalidateMeasure).
The class ContentViewItem extends the ContentView class and sets an object of the Label class to the Content property.
Below is the code of the method Populate, which creates the mentioned matrix:

private void Populate()
{
    itemGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
    itemGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));

    AdaptableGrid innerGrid = new AdaptableGrid();

    ScrollView scroll = new ScrollView();
    scroll.Content = innerGrid;
    itemGrid.Add(scroll);
    int rows = 10;
    int columns = 10;
    int index = 1;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            var item = new ContentViewItem(index++.ToString());
            Grid.SetRow(item, i);
            Grid.SetColumn(item, j);
            innerGrid.Children.Add(item);
            innerGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
        }
        innerGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
    }
}

On Windows the created matrix is only partially visible – two last columns are hidden:

image

The scroll bars are invisible since there is a lot of space and this is a proper behavior.
On Android the linked code works correctly.

Steps to Reproduce

1. Download project from the linked repository.
2. Start the app on Windows.
3. The main page will contain the partially visible matrix.

Link to public reproduction project repository

https://github.com/jns300/Bugs/tree/main/GridAndScrollViewPresentationIssue

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

If the Grid object is not placed inside the ScrollView object then the Grid's children are presented correctly.

Relevant log output

No response

@jns300 jns300 added the t/bug Something isn't working label Oct 6, 2023
@Eilon Eilon added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Oct 6, 2023
@SmartmanApps
Copy link

I didn't even know about AdaptableGrid(!), but I know with a regular Grid it doesn't play nice with ScrollView unless you have allocated all the space. i.e. if you have just 1 row/column of Auto it doesn't work, you have to also have a row/column of Star to make sure all the remaining space has been allocated also, and then the Grid will work correctly in the Scroll. Try something like that.

Also, separate to your issue, I'd suggest adding a BatchBegin() and BatchCommit() to the start/end of your UI processing and it'll speed up your processing a lot!

@jns300
Copy link
Author

jns300 commented Oct 9, 2023

I've made some modifications according to @SmartmanApps suggestions:

private void Populate()
{
    itemGrid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
    itemGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));

    AdaptableGrid innerGrid = new AdaptableGrid
    {
        HorizontalOptions = LayoutOptions.Center,
        VerticalOptions = LayoutOptions.Center,
    };
    ScrollView scroll = new ScrollView();
    scroll.Content = innerGrid;
    itemGrid.Add(scroll);
    int rows = 10;
    int columns = 10;
    int index = 1;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            var item = new ContentViewItem(index++.ToString());
            Grid.SetRow(item, i);
            Grid.SetColumn(item, j);
            innerGrid.Children.Add(item);
            innerGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
        }
        innerGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
    }
}

The below screenshot shows that two last columns still remain hidden:
Screenshot centered

However, when object of the AdaptableGrid class is not centered, then the entire matrix is visible:
image

This doesn't look in a way that can be accepted. It can be considered as another workaround.

@jns300
Copy link
Author

jns300 commented Oct 13, 2023

This issue does not repro on the latest .NET MAUI version (8.0.0-rc.2.9373).

@jns300 jns300 closed this as completed Oct 13, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants