在我的 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;
}
}
这没有帮助