Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackLayout isVisible property not working in Xamarin Forms

I am trying to display popup using AbsoluteLayout. On a button click, Iam setting stacklayout as visible. But its not displayed.

<AbsoluteLayout x:Name="absoluteLayout">
    <StackLayout x:Name="layout1"
             BackgroundColor="White"
             Spacing="1"
             AbsoluteLayout.LayoutBounds="0,0,1,1"
              AbsoluteLayout.LayoutFlags="All">
    <StackLayout>
    <StackLayout x:Name="popupLayout"
             BackgroundColor="Gray"
             AbsoluteLayout.LayoutBounds="0,0,1,1"
             AbsoluteLayout.LayoutFlags="All"
             IsVisible="False"
             Spacing="0">
    //Content
    </StackLayout>
</AbsoluteLayout>

On a button click , Setting visibility to true

public void OnButtonClick(object sender, EventArgs args){
    popupLayout.IsVisible = true;
}

I tried to set visibility of popupLayout to false in OnAppearing and then enabling on button click, still having same behaviour.

Update : Added code detail. By setting background to popupLayout,I came to know that on button click layout is visible, but its content / children are not displayed. Should we have to enable child views / elements separately?

like image 760
user3165999 Avatar asked Dec 02 '25 06:12

user3165999


1 Answers

Try this

public void OnButtonClick(object sender, EventArgs args){
    popupLayout.IsVisible = true;
    popupLayout.ForceLayout();
}

Or

public void OnButtonClick(object sender, EventArgs args){
    popupLayout.IsVisible = true;
    popupLayout.Parent.ForceLayout();
}
like image 143
Atul Avatar answered Dec 04 '25 15:12

Atul