WPF와 js가 창에 호출하는 방법

2207 단어 WPF
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"});

좋은 웹페이지 즐겨찾기