In Xamarin.Forms
, I have an ActivityIndicator
and a label
that pops up when a video is loading. How can I correctly go about disabling it when the video has been fully loaded?
Below is my xaml (Updated 4/26) :
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PreAppStructure"
xmlns:roxv="clr-namespace:Rox;assembly=Rox.Xamarin.Video.Portable"
x:Class="PreAppStructure.Page3"
Title="Welcome to page 3">
<ContentPage.Content>
<Grid>
<roxv:VideoView x:Name="VideoView" AutoPlay="True" LoopPlay="True" ShowController="True" Source="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" />
<StackLayout BackgroundColor="Black" HorizontalOptions="Center" VerticalOptions="Center" IsVisible="True">
<ActivityIndicator Color="White"
x:Name="loader"
IsRunning="{Binding IsBusy}"
VerticalOptions="Center" HorizontalOptions="Center"
/>
<Label x:Name ="loadingtext" Text="Loading...Please wait!" HorizontalOptions="Center" TextColor="White" IsVisible="{Binding IsBusy}"/>
</StackLayout>
</Grid>
</ContentPage.Content>
Below is my C# class, and one of my several attempts:
...
public partial class Page3 : ContentPage
{
public Page3 ()
{
InitializeComponent ();
this.BindingContext = this;
this.IsBusy = true;
NavigationPage.SetBackButtonTitle(this, "Back");
}
async void OnDoSomethingLong()
{
if (!this.IsBusy)
{
try
{
this.IsBusy = true;
//await long operation here
}
finally
{
this.IsBusy = false;
await Task.Run(() => {
return VideoView;
});
}
}
}
You should use IsVisible property for to hide or visible activity indicator
-IsRunning property is used for spin the activity indicator but it won't applicable to hide or visible the activity indicator
in your case use you should use both IsVisible property and IsRunning property, whenever IsBusy is true activity indicator is visible and it will be spin, if it false it won't be visible and spin.
Remove stackLayout and add activity indicator to child of Grid .
<ActivityIndicator Color="White" x:Name="loader"
IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}"
VerticalOptions="Center" HorizontalOptions="Center" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.