1

在我的 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;
    }
}

这没有帮助

4

1 回答 1

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

于 2012-05-11T08:26:59.443 回答