Answered by:
Open new Window from WebBrowser

Question
-
Hello
I display ASP Page in WebBrowser WPF application (MainWindow).
This page contain a button.
On button click, i would like to open another Window (Window1)
Please, how can i do that?
Thanks
Tuesday, November 10, 2015 1:20 PM
Answers
-
Edit: If you want to handle the click of an HTML link, you could hook up an event handler to the HTML element once the document has been loaded as described here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4f0e4d0-78bf-44c5-a3fe-8faf2e7a0568/handling-link-click-event-of-web-browser-control?forum=wpf
You should be able to open another WPF window in an XBAP using the Show() or ShowDialog() method provided that the application is running in full-trust mode (Properties->Security->This is a full trust application).
Please refer to the following page for more information about how to create and deploy a full-trust XBAP: https://msdn.microsoft.com/en-us/library/vstudio/aa970060(v=vs.100).aspx
Then you could implement an ordinary button click event handler:
private void Button_Click(object sender, RoutedEventArgs e) { Window1 win = new Window1(); win.Show(); }
Open new Page from an Xbap: http://stackoverflow.com/questions/303656/open-new-page-from-an-xbap
Hope that helps.Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
- Edited by Magnus (MM8)MVP Tuesday, November 10, 2015 4:57 PM
- Proposed as answer by Xavier Xie-MSFT Friday, November 13, 2015 5:59 AM
- Marked as answer by Xavier Xie-MSFT Friday, November 20, 2015 3:26 AM
Tuesday, November 10, 2015 4:46 PM
All replies
-
The answer is to use objectforscripting.
See:
XAML:
<WebBrowser x:Name="HtmlHost" ObjectForScripting="HtmlInteropClass" />
c#
[System.Runtime.InteropServices.ComVisibleAttribute(True)] Public Class HtmlInteropClass { Public void MyMethod(string SomeValue) { ((MainWindow)Application.Current.MainWindow).SomeTextBox.Text = SomeValue; } }
Your equivalent would, obviously, new up and show a window instead of that.
Javascript
<script type=”text/javaScript”> Function wpfAppMethod(inputValue) { Window.external.MyMethod(inputValue); } </script>
I suppose you could pass the name of the window to open as a string.
Tuesday, November 10, 2015 1:50 PM -
Edit: If you want to handle the click of an HTML link, you could hook up an event handler to the HTML element once the document has been loaded as described here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4f0e4d0-78bf-44c5-a3fe-8faf2e7a0568/handling-link-click-event-of-web-browser-control?forum=wpf
You should be able to open another WPF window in an XBAP using the Show() or ShowDialog() method provided that the application is running in full-trust mode (Properties->Security->This is a full trust application).
Please refer to the following page for more information about how to create and deploy a full-trust XBAP: https://msdn.microsoft.com/en-us/library/vstudio/aa970060(v=vs.100).aspx
Then you could implement an ordinary button click event handler:
private void Button_Click(object sender, RoutedEventArgs e) { Window1 win = new Window1(); win.Show(); }
Open new Page from an Xbap: http://stackoverflow.com/questions/303656/open-new-page-from-an-xbap
Hope that helps.Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
- Edited by Magnus (MM8)MVP Tuesday, November 10, 2015 4:57 PM
- Proposed as answer by Xavier Xie-MSFT Friday, November 13, 2015 5:59 AM
- Marked as answer by Xavier Xie-MSFT Friday, November 20, 2015 3:26 AM
Tuesday, November 10, 2015 4:46 PM