首页 > Windows开发 > 详细

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

时间:2014-08-29 22:35:38      阅读:682      评论:0      收藏:0      [点我收藏+]
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" });

 

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

原文:http://www.cnblogs.com/yuejin/p/3945783.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!