Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

WebView not showing after loading on Absolute and Relative Layout

$
0
0

Hi, I'm trying to show an ActivityIndicator until my webpage finish to load the content. The problem is that the page does not renderer the webview after the content is ready. If the only content of the page is the webview everything works fine, but with the activity indicator the page while loading show correctly the indicator, after it loaded the content the indicator disappear but the webview content is not shown.
Here is the code:

public CommunicationView (string comunicationId)
        {
            _comunicationId = comunicationId;
            _viewModel = new CommunicationViewModel (this,_comunicationId);
            BindingContext = _viewModel;
            _webView = new WebView (){
                VerticalOptions = LayoutOptions.FillAndExpand,
            };
            _webView.SetBinding (WebView.SourceProperty, "HTMLSource");
            Title = "Messaggio";
            var layout = CreateLoadingIndicatorRelativeLayout (_webView);
            Content = layout;
        }

protected AbsoluteLayout CreateLoadingIndicatorRelativeLayout(View content)
        {
            var overlay = new AbsoluteLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            GenerateActivityIndicator();
            _indicator.SetBinding (ActivityIndicator.IsRunningProperty,"Indicator");
            _indicator.SetBinding (ActivityIndicator.IsVisibleProperty, "Indicator");
            //CODE for AbsoluteLayout
            AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            AbsoluteLayout.SetLayoutFlags(_indicator, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(_indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            overlay.Children.Add(content);
            overlay.Children.Add(_indicator);
            /* here in the comment is the code that I use for the RelativeLayout
            overlay.Children.Add(content, Constraint.Constant(0), Constraint.Constant(0));
            overlay.Children.Add(_indicator,
                Constraint.RelativeToParent((parent) => { return (parent.Width / 2) - 16; }),
                Constraint.RelativeToParent((parent) => { return (parent.Height / 2) - 16; }));*/
            return overlay;
        }

Here the view Model:

public class CommunicationViewModel : ViewModel
    {
        CommunicationView _view;
        string _comunicationId;

        public CommunicationViewModel (CommunicationView view,string comunicationId)
        {
            _view = view;
            Indicator = true;
            _comunicationId = comunicationId;
            AcquireHtmlContent ();
        }

        private bool _indicator;
        public bool Indicator{
            get{ return _indicator; }
            set{ ChangeAndNotify (ref _indicator,value); }}



        private HtmlWebViewSource _htmlSource;
        public HtmlWebViewSource HTMLSource { 
            get{ return _htmlSource; }
            set{ ChangeAndNotify (ref _htmlSource,value); }
        }

        public async void ConfirmCommunicationRead(){
            var ws = IoC.Resolve<IWebServicesFactory>().Create();
            var result = await ws.ConfirmCommunicationRead (_comunicationId);
            MessagingCenter.Send (this, "CommunicationRead",_comunicationId);
        }

        private async Task AcquireHtmlContent(){
            var ws = IoC.Resolve<IWebServicesFactory>().Create();
            var result = await ws.GetCommunication (AppContext.ClubCode, AppContext.SubscriberCode, _comunicationId);
            if (string.IsNullOrEmpty(result.HTMLText)) {
                MessageBox.ShowError ("Non è stato possibile recuperare le informazioni della comunicazione", _view);
            } else {
                var htmlSource = new HtmlWebViewSource ();
                htmlSource.Html = result.HTMLText;
                Indicator = false;
                HTMLSource = htmlSource;
                NotifyPropertyChanged ("");
            }
        }

If the content of the page is only the WebView everythings works fine.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>