3

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?

user3165999
  • 149
  • 4
  • 11
  • 1
    I am pretty sure it is IsVisible="false" with ->"<- If you miss that, you may have a compiler issue. I have applied IsVisible on StackLayouts and Grids in the past and never experience issues with that. But you may also check this post http://stackoverflow.com/questions/29006354/toggling-isvisible-for-an-stacklayout-inside-scrollview-does-not-update-properly just in case you are on an older version of Xamarin. – eX0du5 Sep 28 '16 at 06:20
  • It seems strange that you don't give any `AbsoluteLayout.LayoutBounds` to any of the `AbsoluteLayout` Children. What happen if you do so ? – Stephane Delcroix Sep 28 '16 at 06:43
  • I have represented my code in this format for simplification. LayoutBounds are actually defined – user3165999 Sep 28 '16 at 07:05
  • @eX0du5 That was a mistake while adding code here in simple form – user3165999 Sep 28 '16 at 07:16

1 Answers1

3

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();
}
Atul
  • 440
  • 8
  • 24