- 方法一
直接设置控件的NavigateUri属性,代码如下
1<UserControl x:Class="SLOpenNewWindow.Page"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 Width="400" Height="300">
5 <Canvas Width="400" Height="300" Background="Bisque" >
6 <Border Canvas.Top="120" Canvas.Left="100" BorderBrush="Crimson" BorderThickness="2">
7 <HyperlinkButton NavigateUri="http://www.cnblogs.com/wsdj-ITtech/" Content="Click Me" TargetName="_blank" FontSize="28" Height="50" Width="150"></HyperlinkButton>
9 </Border>
10 </Canvas>
11</UserControl>
- 方法二
添加控件的Click事件,并在事件中编写后台代码
控件代码如下:
<UserControl x:Class="SLOpenNewWindow.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas Width="400" Height="300" Background="Bisque" >
<Border Canvas.Top="120" Canvas.Left="100" BorderBrush="Crimson" BorderThickness="2">
<HyperlinkButton Content="Click Me" TargetName="_blank"
Click="HyperlinkButton_Click" FontSize="28" Height="50" Width="150"></HyperlinkButton>
</Border>
</Canvas>
</UserControl>
Click事件后台代码如下:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Eval("window.open(\"http://www.cnblogs.com/wsdj-ITtech/\")");
}
{
HtmlPage.Window.Eval("window.open(\"http://www.cnblogs.com/wsdj-ITtech/\")");
}
要引入命名空间:System.Windows.Brower;