WPF和js交互 调用窗体中的方法


public partial class WebTest: Window
{
   private void Window_ContentRendered(object sender, EventArgs e)
   {
     this.wbrExam.ObjectForScripting = new OprateBasic(this);
     this.wbrExam.Source = new Uri(Environment.CurrentDirectory + @"\res\template.html");
   }
   
   public void Wtest(string str)
   {
        MessageBox.Show(str);
   }
}

[System.Runtime.InteropServices.ComVisible(true)]
public class OprateBasic
{
    private WebTest instance;
    public OprateBasic(WebTest instance)
    {
       this.instance = instance;
    }
    
    public void HandleTest(string p)
    {
        instance.Wtest(p);
    }
}

js->cs:window.external.HandleTest(“测试”);

cs->js:this.wbrExam.InvokeScript("js方面名", new object[] { "hello" });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM