HybidWebView for two way communication from C# to JS and vice versa

SurbhiAroraaSurbhiAroraa Member ✭✭✭

How to achieve both way communication in WebView with single control i.e. to call C# function from Javascript and call Javascript function from C#. Any leads will be appreciated much. @JamesMontemagno

Answers

  • Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

    Hi @SurbhiArora
    JavaScript code in webview
    function playAudio() { wavesurfer.play(); } function pauseAudio() { wavesurfer.pause(); }
    c# code to call js code here Waveform refers webview page
    `private static void IsPlayPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
    if ((bool)newValue)
    ((Waveform)bindable).PlayAudio();
    else
    ((Waveform)bindable).PauseAudio();

        }`
    

    <?xml version="1.0" encoding="UTF-8"?> <Grid xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Controls.Waveform" > <WebView x:Name="webview"></WebView> </Grid>

Sign In or Register to comment.