Skip to content

Instantly share code, notes, and snippets.

@andreburto
Created January 19, 2018 20:25
Show Gist options
  • Select an option

  • Save andreburto/9a8d73fc7a016b543a403f6d7b131064 to your computer and use it in GitHub Desktop.

Select an option

Save andreburto/9a8d73fc7a016b543a403f6d7b131064 to your computer and use it in GitHub Desktop.
function main{
Add-Type -AssemblyName presentationframework
$html = [string]@"
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<script>
function btnClick() {
var body = document.body;
body.innerHTML += "<p>Hello, World!";
}
</script>
</head>
<body>
<button onclick="btnClick();">Click Me!</button>
</body>
</html>
"@
$xaml = [xml]@"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<DockPanel>
<WebBrowser Name="wbSample"></WebBrowser>
</DockPanel>
</Window>
"@
$reader = New-Object System.Xml.XmlNodeReader $xaml
$form = [Windows.Markup.XamlReader]::Load($reader)
#Form Objects
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$form.add_KeyDown{
param([Parameter(Mandatory)][Object]$sender, [Parameter(Mandatory)][Windows.Input.KeyEventArgs]$e)
if ($e.Key -eq 'Escape')
{
$form.Close()
}
}
#$wbSample.Navigate("https://www.google.com")
$wbSample.NavigateToString($html)
$form.ShowDialog() | Out-Null
}
. main
# For later: http://www.dotnetfunda.com/articles/show/840/working-with-webbrowser-in-wpf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment