8,707
社区成员




[PermissionSet(SecurityAction.Demand,Name="FullTrust")]
[ComVisibleAttribute(true)]
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.webBrowser.ObjectForScripting = this;
this.webBrowser.Navigate(new Uri(Environment.CurrentDirectory + @"\default.html"));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
HtmlDocument document = this.webBrowser.Document;
document.InvokeScript("JSCallWPF", null);
}
public void JsCallWPF()
{
System.Windows.MessageBox.Show("JS CALL WPF");
}
}
<Window x:Class="TestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:host="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:winControl="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="MainWindow" Height="400" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<host:WindowsFormsHost Grid.Row="0">
<winControl:WebBrowser x:Name="webBrowser"/>
</host:WindowsFormsHost>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Content="Js call WPF" Click="Button_Click"/>
</StackPanel>
</Grid>
</Window>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function JSCallWPF() {
window.external.JsCallWPF();
}
</script>
</head>
<body>
<div id="footer">
<p>CopyRight(c)2003-2008, GrapeCity inc,All rights reserved</p>
</div>
</body>
</html>
看样子好像是权限问题。这咋解决呢?