Grouping Controls without affecting how they are displayed

BrienKingBrienKing ✭✭USMember ✭✭
edited September 11 in Xamarin.Forms

I want to group controls together so that I can set the IsEnabled and/or isVisible property on the Parent container and have it applied to the children.

So I would have some XAML like this:

        <StackLayout Padding="8,0,8,0">
            <Image Source="@drawable/logo.png" HorizontalOptions="Center" VerticalOptions="Center"></Image>
            <ControlGroup x:Name="FirstGroup">
                <ActivityIndicator x:Name="BusyIndicator" />
                <Label x:Name="StatusLabel" Text="{i18n:Translate PleaseWait}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="Large" ></Label>
            </ControlGroup>
            <ControlGroup x:Name="SecondGroup">
                <Label x:Name="LoginLabel" Text="{i18n:Translate EnterYourPin}" VerticalOptions="Start" FontSize="Large"/>
                <Entry x:Name="PinEdit" IsPassword="True" Keyboard="Numeric" MaxLength="10"/>
                <Button x:Name="LoginButton" Text="{i18n:Translate Login}" Clicked="Button_Clicked"></Button>
            </ControlGroup>
        </StackLayout>

Then I could do FirstGroup.IsVisible = false; to hide all the children in that group at one time.

Is there a control already available that does this? Everything I looked at so far effects how it's displayed (such as putting them in a Grid).

Best Answer

Answers

  • BrienKingBrienKing ✭✭ USMember ✭✭
    edited September 12

    Thank you for your response. The thing I was missing is that you cannot have 2 or more StackLayouts in the root like this:

        <ContentPage.Content>
            <StackLayout>
            </StackLayout>
            <StackLayout>
    
            </StackLayout>
        </ContentPage.Content>
    
    

    but you can nest multiple within a StackLayout like this:

        <ContentPage.Content>
            <StackLayout>
                <StackLayout>
    
                </StackLayout>
                <StackLayout>
    
                </StackLayout>
            </StackLayout>
        </ContentPage.Content>
    

    That's what I was missing. Odd that nesting works but not having multiple at the root. Maybe a limitation of the ContentPage?

  • JarvanJarvan Xamurai Member, Xamarin Team Xamurai
    edited September 12

    Odd that nesting works but not having multiple at the root. Maybe a limitation of the ContentPage?

    ContentPage is a Page that displays a single view. To put multiple content in contentpage, use layout class derive from Layout.

    Check the tutorial:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/controls/layouts

Sign In or Register to comment.