public MainPage()
{
InitializeComponent();
//wb is the webbrowser
wb.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(wb_LoadCompleted);
//pretty sure you need this somewhere other than the constructor, or you'll get that
//"cannot navigate until in visual tree" exception
wb.NavigateToString(MyHTMLString);
}
void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
wb.Navigating += new EventHandler<NavigatingEventArgs>(wb_Navigating);
}
void wb_Navigating(object sender, NavigatingEventArgs e)
{
e.Cancel = true;
}
Идея в основном такова.переопределите LoadCompleted
, и после страницы, которую вы хотите загрузить, убедитесь, что ни на одной другой странице нельзя перейти, установив e.Cancel
внутри события Navigating
.