2017-07-24 44 views
1

我想在WebView加載數據時首先加載活動指示器,然後加載數據後它變爲不可見。加載WebView時的活動指示器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" Title="Shows Trending" xmlns:o="clr-namespace:Octane.Xam.VideoPlayer;assembly=Octane.Xam.VideoPlayer" x:Class="BBSTV.TrendingShowsDetails"> 
    <ActivityIndicator x:Name="activity_indicator" Color="Blue" /> 
    <WebView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" x:Name="loadVideo_wv"> 
    </WebView> 
</ContentPage> 

下面是我的C#代碼:

using System; 
using System.Collections.Generic; 

using Xamarin.Forms; 

namespace BBSTV 
{ 
    public partial class TrendingShowsDetails : ContentPage 
    { 
     public TrendingShowsDetails(string videolink) 
     { 
      InitializeComponent(); 
      activity_indicator.IsRunning = true; 
      loadVideo_wv.Source = "https://www.youtube.com/playlist?list=" + videolink; 
      activity_indicator.IsRunning = false; 
     } 
    } 
} 

回答

1

試試這個:

C#代碼:

public TrendingShowsDetails(string videolink) 
     { 
      InitializeComponent(); 

      loadVideo_wv.Source = "https://www.youtube.com/playlist?list=" + videolink; 

     } 


     protected async override void OnAppearing() 
     { 
      base.OnAppearing(); 
      await activity_indicator.ProgressTo(0.9, 900, Easing.SpringIn); 

     } 

     public void OnNavigating(object sender, WebNavigatingEventArgs e) 
     { 
      activity_indicator.IsVisible = true; 


     } 

     public void OnNavigated(object sender, WebNavigatedEventArgs e) 
     { 

      activity_indicator.IsVisible = false; 

     } 

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" 
    Title="Shows Trending" xmlns:o="clr-namespace:Octane.Xam.VideoPlayer;assembly=Octane.Xam.VideoPlayer" x:Class="BBSTV.TrendingShowsDetails"> 
    <StackLayout> 
    <ProgressBar Progress="0.2" IsVisible="false" HorizontalOptions="FillAndExpand" x:Name="activity_indicator" /> 

    <WebView VerticalOptions="FillAndExpand" Navigating="OnNavigating" Navigated="OnNavigated" HorizontalOptions="FillAndExpand" x:Name="loadVideo_wv"> 
    </WebView> 
    </StackLayout> 
</ContentPage> 
相關問題