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

Grid: Provide information for the actual height of RowDefinition and actual width of ColumnDefinition #25982

Open
eli-popova opened this issue Nov 20, 2024 · 1 comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter partner Issue or Request from a partner team proposal/open

Comments

@eli-popova
Copy link

eli-popova commented Nov 20, 2024

Description

Currently, we can set the Height property of a RowDefinition object and the Width property of a ColumnDefinition object with some value and a unit type of Absolute, Star and Auto. What we need, however, is to have information about the real sizes of rows/columns in the grid after it has been measured. In WinUI and WPF we have a public API providing such information. It would be great if we had this in MAUI as well.

Public API Changes

public sealed class RowDefinition
{
   ...
   public double ActualHeight { get; private set; }   ---> the calculated height of the row after the grid has been measured and arranged
   ...
}
public sealed class ColumnDefinition
{
    ...
    public double ActualWidth { get; private set;}    ---> the calculated width of the column after the grid has been measured and arranged
    ...
}

Intended Use-Case

We need this information as we are developing a GridSplitter control. To resize rows/columns by dragging the splitter we need to know their exact sizes.

@PureWeen PureWeen added partner Issue or Request from a partner team area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter labels Nov 20, 2024
@PureWeen PureWeen added this to the .NET 10 Planning milestone Nov 20, 2024
@maxiptah
Copy link

Same problem here. I needed this control just for my own application and I came up with this partial workaround: if in the containing grid your rows are all measured absolutely or in stars, you can calculate the actual row height by substracting all absolute heights of other rows and dividing the remaining space by the remaining number of stars. Works for me, but will break with "Auto" sized rows..

   private double GetActualRowHeight(Grid grid, int rowIndex)
   {
       var height = grid.RowDefinitions[rowIndex].Height;
       if (height.IsAbsolute)
       {
           return height.Value;
       }

      if (height.IsAuto) 
     {
           throw new NotImplementedException();
     }

       var totalStars = 0;
       var remainingHeight = grid.Height;
       foreach (var rowDefinition in grid.RowDefinitions)
       {
           if (rowDefinition.Height.IsAbsolute)
           {
               remainingHeight -= rowDefinition.Height.Value;
           }
           else if (rowDefinition.Height.IsStar)
           {
               totalStars += (int)rowDefinition.Height.Value;
           }
           else if (row definition.Height.IsAuto)
           {
              throw new NotImplementedException();
              // Need to calculate based on children, which I'm not sure is reliably possible
           }
       }

       return totalStars > 0
           ? remainingHeight / totalStars
           : remainingHeight;
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter partner Issue or Request from a partner team proposal/open
Projects
None yet
Development

No branches or pull requests

3 participants