1

取消导航在我的RichTextBox的代码在我的Windows Phone应用程序,我有:如何在RichTextBox中

var link = new Hyperlink(); 
         if (!string.IsNullOrEmpty(linkUrl)) 
         { 
          link.NavigateUri = new Uri(linkUrl); 
         } 
         link.Foreground = new SolidColorBrush(Colors.Blue); 
         link.TargetName = "_blank"; 

         var linkText = new Run() { Text = linkDesc }; 
         link.Inlines.Add(linkText); 
         link.Click += new RoutedEventHandler(NavidateTo); 

         paragraph.Inlines.Add(link); 

private static void NavidateTo(object sender, RoutedEventArgs routedEventArgs) 
     { 

      if (MessageBox.Show(
          Constants.BrowserNavigating, 
          "", 
           MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) 
      { 
       //cancel Navigation 
      } 
      else 
      { 
       StateManager.Set("Browser", "true"); 
      } 
     } 

如何取消导航NavidateTo方法?

更新

私有静态无效NavidateTo(对象发件人,RoutedEventArgs routedEventArgs) {

if (MessageBox.Show(
        Constants.BrowserNavigating, 
        "", 
         MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) 
    { 
     //cancel Navigation 
     var phoneApplicationFrame = Application.Current.RootVisual as PhoneApplicationFrame; 
     if (Application.Current.RootVisual as PhoneApplicationFrame != null) 
      phoneApplicationFrame.Navigating += new NavigatingCancelEventHandler(NavigationService_Navigating); 
    } 
    else 
    { 
     StateManager.Set("Browser", "true"); 
    } 
} 

public static void NavigationService_Navigating(object sender, NavigatingCancelEventArgs e) 
{ 
    { 
     e.Cancel = true; 
    } 
} 

这不利于

回答

0

使用this.NavigationService.StopLoading();

也可以考虑这种方法:

订阅Navigating事件。

void NavigationService_Navigating(object sender, NavigatingCancelEventArgs e) 
{ 
    // Don't allow refreshing of a static page 
    if (DO SOME CHECKS) 
     { 
      e.Cancel = true; 
     } 
} 

并看看这篇文章在msdn。

http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.navigating.aspx

+0

它在任何情况下navagete,看到我更新 – revolutionkpi

+0

看看NavigationService.Navigating,你可以e.Cancel = TRUE;它... – animaonline

+0

超链接没有这个事件! – revolutionkpi