Xamarin.Forms.WebView初始加载指示器 [英] Xamarin.Forms.WebView initial loading indicator

查看:139
本文介绍了Xamarin.Forms.WebView初始加载指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用Xamarin表单WebView并为首次加载添加加载进度栏的最简单方法是什么?

What is the simplest way for me to take a Xamarin forms WebView and add a loading progress bar for the first load?

我的应用程序只是包装了一个网站,但在启动画面消失并且WebView正在加载其内容的带宽不佳的情况下,我当然会看到一个白屏.

My application simply wraps a website but in poor bandwidth scenarios when the splash screen disappears and the WebView is loading it's content I of course see a white screen.

我希望看到进度指示器.我环顾四周,但没有找到简单的解决方案,而且大多数问题都不针对Xamarin.Forms.

I would like to see a progress indicator. I have looked around but haven't found a simple solution to this and most questions are not oriented towards Xamarin.Forms.

谢谢.

亲切的问候, 标记

推荐答案

只需将StackLayoutActivityIindicatorWebView用作子项,并根据在 WebView.Navigating WebView.Navigated 事件中设置的IsWorking属性值设置其可见性.您的ViewModel必须实现IOnPropertyChanged.

Just use StackLayout with ActivityIindicator and WebView as children and set it's visibility based on IsWorking property value which is set in WebView.Navigating and WebView.Navigated events. Your ViewModel has to implement IOnPropertyChanged.

var webViewView = new WebView() {
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.FillAndExpand,
};
webViewView.SetBinding<YourViewModel>(View.IsVisibleProperty, v => v.IsWorking, 
    BindingMode.OneWay, new Converters.NegateBoolConverter());

webViewView.Navigating += (sender, e) => {
    viewModel.IsWorking = true;
};

webViewView.Navigated += (sender, e) => {
    viewModel.IsWorking = false;
};

var activityIndicator = new ActivityIndicator() {
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
};
activityIndicator.SetBinding<YourViewModel>(ActivityIndicator.IsRunningProperty, v => v.IsWorking);

var isWorkingView = new ContentView() {
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.FillAndExpand,
    Content = activityIndicator
};
isWorkingView.SetBinding<YourViewModel>(ContentView.IsVisibleProperty, v => v.IsWorking);

var root = new StackLayout() {
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.FillAndExpand,
    Children = {
        webViewView,
        isWorkingView,
    }
};

这篇关于Xamarin.Forms.WebView初始加载指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆