【发布时间】:2018-04-26 01:27:19
【问题描述】:
在Xamarin.Forms 中,我有一个ActivityIndicator 和一个label,在加载视频时会弹出。视频完全加载后,如何正确禁用它?
以下是我的 xaml (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>
下面是我的 C# 类,也是我的几次尝试之一:
...
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;
});
}
}
}
【问题讨论】:
-
你不知道如何禁用ActivityIndicator?还是您不确定视频何时完成加载?还是两者兼而有之?
-
我相信我用“this.IsBusy = false;”行禁用了 ActivityIndicator,我想说后者是我有点模糊的。我的直觉告诉我视频已在“返回 VideoView”处完成加载,所以我认为 IsBusy 代码行会在此之后进行,但这是不正确的。上线前我也试过了,没有运气。
-
控件是否完全消失,或者是否它们消失了,但不是您希望它们消失的时间?
-
您可以像 IsRunning 一样使用 IsVisible 属性来更改可见性。只需在 XAML 活动指示器
中添加代码。它有效 -
因为你并没有真正展示加载视频的代码,所以很难说它什么时候完成
标签: c# xaml xamarin binding xamarin.forms