1

我试图在我的配置下载后隐藏StackLayout调用InfoStackLayout,显示 5s 的信息标签,但是在隐藏Infostack在代码中之后,我Grid的 inContentPage不会刷新视图并留下空白空间。(InfoStackLayout不可见但仍保留空间)更糟糕的是,按钮ButtonsStack无法正确响应点击事件。锁定和解锁手机后,一切正常。

<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;
});
4

1 回答 1

1

@Shan的回答是最好的解决方案。只需将 Task.Factory.StartNew 替换为 Device.BeginInvokeOnMainThread 即可。

于 2018-10-30T13:49:16.863 回答