Xamarin 进度条进入覆盖层不可见

本文关键字:Xamarin 覆盖 | 更新日期: 2023-09-27 17:56:46

in Xamarin当我按下按钮时,我想显示带有简单进度条的覆盖层。

这是我的 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>

这是按钮点击功能

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

问题是当我单击按钮时,会显示叠加层,但进度条没有!为什么?

Xamarin 进度条进入覆盖层不可见

好的,我已经找到了解决方案..简单地说,我已经将Xamarin.Forms更新为Nuget包