locked
OnElementPropertyChanged event handler looping round in customrenderer RRS feed

  • Question

  • User380797 posted

    The below code is for custom webview renderer for UWP :

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var customWebView = Element as PdfView; Control.Source = new Uri(string.Format("ms-appx-web:///pdfjs/web/viewer.html?file={0}", string.Format(customWebView.Uri)));

        }
    

    But this method is looping round(Executing multiple times). Any suggestion please................

    Friday, January 10, 2020 12:31 PM

Answers

  • User369978 posted

    OnElementPropertyChanged is called when a element property has changed (include the initialization of property) , you could put your code into OnElementChanged method.

     protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);
    
    
            if (e.NewElement != null)
            {
                var customWebView = Element as PdfView;
                Control.Source = new Uri(string.Format("ms-appx-web:///pdfjs/web/viewer.html?file={0}", string.Format(customWebView.Uri)));
            }
        }
    

    Check https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview#create-the-custom-renderer-on-uwp.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 10, 2020 1:42 PM