我将 WPF WebBrowser 控件拖到我的 Blend 项目中,然后将源分配为 HTML5 页面。我想在我的 WPF 应用程序中使用 LobsterPot HTML5 PivotViewer(url: LobsterPot HTML5 PivotViewer)。
页面加载,然后我在浏览器顶部收到一条通知,说活动内容已被阻止,当我单击允许时,屏幕保持空白。屏幕上不显示任何内容。任何人都可以指导我并解释我哪里出错了......
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CheckLobster.MainWindow"
x:Name="Window"
Width="640" Height="480" UseLayoutRounding="True" WindowStartupLocation="CenterScreen" WindowState="Maximized" Title="HTML 5 Pivot Viewer Sample"
ResizeMode="CanResizeWithGrip">
<StackPanel Orientation="Vertical" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal">
<Button x:Name="BackButton" Content="Back" Margin="5" Cursor="Hand" ToolTip="Press this button to navigate to the previous page" FontWeight="ExtraBold" MouseLeftButtonDown="BackButton_MouseLeftButtonDown"/>
<Button x:Name="NextButton" Content="Next" Margin="5" Cursor="Hand" ToolTip="Press this button to navigate to the next page." FontWeight="ExtraBold" MouseLeftButtonDown="NextButton_MouseLeftButtonDown"/>
<TextBox x:Name="UriFieldTextBox" TextWrapping="Wrap" Margin="10,5,5,5" VerticalContentAlignment="Stretch" ToolTip="Enter the Web Address that you wanted to navigate to and press the Go Button" HorizontalAlignment="Right" MinWidth="300"/>
<Button x:Name="GoButton" Content="Go" HorizontalAlignment="Right" Margin="5" FontWeight="ExtraBold" ToolTip="Press this button to navigate to the specified page." Cursor="Hand" MouseLeftButtonDown="GoButton_MouseLeftButtonDown"/>
</StackPanel>
<WebBrowser x:Name="MyWebBrowser" Margin="0" MinHeight="600" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Loaded="MyWebBrowser_Loaded" />
</StackPanel>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void BackButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// TODO: Add event handler implementation here.
MyWebBrowser.GoBack();
}
private void GoButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// TODO: Add event handler implementation here.
MyWebBrowser.Navigating += new NavigatingCancelEventHandler(MyWebBrowser_Navigating);
MyWebBrowser.Navigated += new NavigatedEventHandler(MyWebBrowser_Navigated);
string address = UriFieldTextBox.Text.ToString().Trim();
MyWebBrowser.Navigate(new Uri(address,UriKind.RelativeOrAbsolute));
}
private void NextButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// TODO: Add event handler implementation here.
MyWebBrowser.GoForward();
}
private void MyWebBrowser_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
// TODO: Add event handler implementation here.
MyWebBrowser.Navigating += new NavigatingCancelEventHandler(MyWebBrowser_Navigating);
MyWebBrowser.Navigated+=new NavigatedEventHandler(MyWebBrowser_Navigated);
Uri uri = new Uri("C:\\Users\\Manthravadi\\Desktop\\lobsterpothtml5pivotviewer-0.6.8\\examples\\PASS Summit 2011.html",UriKind.Absolute);
MyWebBrowser.Source= uri;
}
void MyWebBrowser_Navigating(object sender,NavigatingCancelEventArgs args){
MessageBox.Show("Page is Loading ...\n\nPlease wait");
}
void MyWebBrowser_Navigated(object sender, NavigationEventArgs args){
MessageBox.Show("Page has been Loaded ...!");
}
此外,当我在 UriFieldTextBox 中键入诸如“http://google.com”(不带引号)之类的地址并按“执行”按钮时,没有加载页面,有人可以解释我哪里出错了吗?
~ 哈沙