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

时间:2014-08-29 22:35:38   收藏:0   阅读:251
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" });

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!