如何在RichTextBox中取消导航

时间:2012-05-11 08:16:19

标签: c# silverlight windows-phone-7 silverlight-4.0 silverlight-3.0

在我的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方法中取消导航?

更新

private static void NavidateTo(object sender,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;
    }
}

这没有帮助

1 个答案:

答案 0 :(得分: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