加载WebView Xamarin表单时的活动指示器

时间:2017-07-24 14:47:43

标签: c# webview xamarin.forms activity-indicator

我想在WebView加载数据时首先加载一个Activity指标,然后在加载数据后变为Invisible。

以下是我的Xaml代码:

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

以下是我的C#代码:

{{1}}

2 个答案:

答案 0 :(得分:2)

试试这个:

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>

答案 1 :(得分:1)