1

I'm trying to hide StackLayout called InfoStackLayout after my config is downloaded, displaying information label for 5s, but after hiding Infostack in code, my Grid in ContentPage doesn't refresh the view and leaves empty space. (the InfoStackLayout is invisible but still reserves the space) Even worse, buttons in ButtonsStack doesn't respond correctly to clicked events. After locking and unlocking phone everything works as it should.

<Grid x:Name="RootGrid" VerticalOptions="Fill" RowSpacing="0" ColumnSpacing="0">
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
  </Grid.RowDefinitions>
  <StackLayout x:Name="InfoStackLayout" Grid.Row="0" Orientation="Horizontal">
    <Label x:Name="InfoLabel" TextColor="White" HorizontalOptions="StartAndExpand" Font="18" />
    <Image x:Name="GetConfig" HorizontalOptions="EndAndExpand" Source="loading.png" HeightRequest="32" WidthRequest="32">
      <Image.GestureRecognizers>
        <TapGestureRecognizer Tapped="ReloadConfig_Tapped" NumberOfTapsRequired="1"/>
      </Image.GestureRecognizers>
    </Image>
  </StackLayout>
  <StackLayout x:Name="ButtonsStack" Grid.Row="1">
  </StackLayout>
</Grid>
InfoLabel.Text = "Download Config";
Device.StartTimer(TimeSpan.FromSeconds(5), () =>
{
    Task.Factory.StartNew(async () =>
    {
        await InfoStackLayout.FadeTo(0);
        InfoStackLayout.IsVisible = false;
        InfoStackLayout.HeightRequest = 0;
    });
    return false;
});
3
  • Use YourViewOrLayout.ForceLayout(); when you are showing/hiding.
    – NKR
    Commented Oct 29, 2018 at 16:29
  • Any update to the UI must be done on the main thread. Wrap the hiding logic in InvokeOnMainThread method.
    – Ranga
    Commented Oct 29, 2018 at 17:39
  • @Shan Thank you! Replacing Task.Factory.StartNew with Device.BeginInvokeOnMainThread done the job :)
    – user9479448
    Commented Oct 30, 2018 at 13:05

1 Answer 1

1

@Shan answer was the best solution. Just replacing Task.Factory.StartNew with Device.BeginInvokeOnMainThread do the trick.