在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却没有!为什么?
https://stackoverflow.com/questions/38345416
复制相似问题