如何在不使用Web浏览器控件的情况下调用wpf中的脚本和html

时间:2018-03-28 06:44:01

标签: c# wpf

我正在使用此代码。

C#代码 这里我附上了html,c#和xaml代码。你能参考一下吗

private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                string curdir = Directory.GetCurrentDirectory();
                webBrowser.Navigate(String.Format("file:///{0}/sample.html", curdir));         
            }
            private void btngetdatafrombrowser_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    dynamic objdata = webBrowser.InvokeScript("GetData");
                    if (objdata != null)
                        MessageBox.Show(objdata);
                }
                catch (Exception ezx)
                {

                }
            }

    <!DOCTYPE html>
    <!-- saved from url=(0014)about:internet -->
    <html oncontextmenu="return false" ;>
    <head>
        <title>Testing</title>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11,IE=9; IE=8; IE=7; IE=EDGE" />
        <link rel="stylesheet" type="text/css" href="style.css">

    </head>
    <body> 
        <center>
            <form>
                <fieldset class="account-info">
                    <label>
                        Select the File
                        <input type="file" id="inputfile" onchange="ReadFile()" />
                    </label>

                </fieldset>

            </form>
        </center>
           <script>
            //Get Sample Function
            function GetSampleFunction() {
                return "Bala";
            }
            //Property Variable
            var rawData = undefined;
            var fr;
            //GetData For Select File
            function GetData() {
                          return "data";
            }
            //read data for select File
            function ReadFile() {
                var upload = document.getElementById('inputfile');
                var f = upload.files[0], read = new FileReader();
                fr = new FileReader();
                fr.onload = function () {
                    rawData = fr.result;
                };
                fr.readAsArrayBuffer(f);
          }


        </script>
    </body>
    </html>

      <WebBrowser x:Name="webBrowser" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" ObjectForScripting="HtmlInteropClass" Navigated="webBrowser_Navigated" Navigating="webBrowser_Navigating">
                <WebBrowser.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform Angle="-0.018"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </WebBrowser.RenderTransform>
            </WebBrowser>
            <Button Grid.Row="1" Name="btngetdatafrombrowser" Click="btngetdatafrombrowser_Click" Background="SkyBlue" Foreground="White" FontSize="34">Getdata</Button>

但是我不想使用它。可以在wpf应用程序中执行此操作,而无需使用Web浏览器控件。

这件事发生在使用网络浏览器控制但不应使用网络浏览器

0 个答案:

没有答案