Xamarin ProgressBar进入叠加层是不可见的

时间:2016-07-13 07:38:06

标签: c# xaml xamarin cross-platform

在Xamarin中按下按钮我想用简单的ProgressBar显示叠加层。

这是我的XAML布局

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="AbsoluteXamlDemo.SimpleOverlayPage">
<AbsoluteLayout>

<StackLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">

  <Label FontSize="Medium" VerticalOptions="CenterAndExpand" HorizontalOptions="Center">This might be a page full of user-interface objects except that the only functional user-interface object on the page is a Button</Label>
  <Button Text="Run 5-Sec job" FontSize="Large" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Clicked="OnButtonClicked"></Button>
  <Button Text="A DO-Nothing Btn" FontSize="Large" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" ></Button>
  <Label FontSize="Medium" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Center" >This continues the page full of user-interface objects except that the only functional user-interface object on the page is the Button.</Label>

</StackLayout>

<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" IsVisible="False" BackgroundColor="#C0808010" Padding="10,0">
  <ProgressBar x:Name="ProgressBar" VerticalOptions="Center"></ProgressBar>
</ContentView>
</AbsoluteLayout>

这是OnButtonClicked函数

        overlay.IsVisible = true;

        TimeSpan duration = TimeSpan.FromSeconds(5);
        DateTime startTime = DateTime.Now;

        Device.StartTimer(TimeSpan.FromSeconds(0.1), () =>
        {                
            double progress = (DateTime.Now - startTime).TotalMilliseconds / duration.TotalMilliseconds;
            ProgressBar.Progress = progress;
            bool continueTimer = progress < 1;
            if (!continueTimer)
            {
                // Hide overlay. 
                overlay.IsVisible = false;
            }
            return continueTimer;
        });

问题是,当我点击按钮时,会显示叠加层,但ProgressBar不会出现!为什么呢?

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案..我只是将Xamarin.Forms更新为Nuget包