Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to hide a Row or Column in a grid layout?

In XAML Windows it is possible to hide a row or column in a GridLayout.
Is this possible with Xamarin.Forms?
So far I found out that I had to hide all controls inside an set height (for a row) to 0; but that's not a clean solution.

Posts

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    There is currently not an API to hide/show a row/column.

  • Natalia.NovosadNatalia.Novosad USUniversity

    Hi,

    Is there a way to hide/show entire Grid (or maybe some other content container) in XAML markup depending on some property value, like in WPF apps (applying triggers or styles/templates)?

  • AndrewMcCormackAndrewMcCormack USUniversity ✭✭✭

    set the height to 0

  • Neuron1444Neuron1444 MDMember

    Set RowSpacing="0" and Height="0"

  • MattButlerMattButler USUniversity ✭✭

    FYI, setting the RowSpacing and/or Height yielded no results for me.

  • SagarPanwalaSagarPanwala USMember ✭✭✭

    Does this have answer now?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @SagarPanwala said:
    Does this have answer now?

    Make the height of the second row to 0 would hide it...

    Grid g = new Grid
                {
                    RowDefinitions = {
                        new RowDefinition { Height = new GridLength(50, GridUnitType.Absolute)},
                        new RowDefinition { Height = new GridLength(30, GridUnitType.Absolute)},
                    }
                };
    
                g.RowDefinitions[1].Height = 0;
    
  • avelezdoavelezdo ESMember

    Thank you @NMackay. That works like a charm!

  • IvanFranchiIvanFranchi USMember ✭✭

    Why not like this: YourGrid.ColumnDefinitions.RemoveAt(5); where YourGrid is your grid and 5 is the column you want to remove. It worked for me properly aligning the items

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    @IvanFranchi how can I use the same but to remove by RowDefinition's name, like this:

    YourGrid.ColumnDefinitions.RemoveAt("RowFirstName");
    YourGrid.ColumnDefinitions.RemoveAt("RowLastName");

  • IvanFranchiIvanFranchi USMember ✭✭
    edited August 2018

    YourGrid.Children.Remove(ComponentName);
    Where component name references what you want to remove so no quotation marks. Children let you Add, Insert, Clear...really useful while working with grids.
    Another way could be by cycling through the elements of your grid, find the ones with the property you want and then remove by index (index given by the cycle) but we can already access by View Item (ComponentName) as said above

  • loladekingloladeking Member ✭✭

    Thanks . @NMackay worked perfectly

Sign In or Register to comment.