/// <summary> /// Performs navigation to specified link. /// </summary> /// <param name="uri">The uri to navigate to.</param> /// <param name="source">The source element that triggers the navigation. Required for frame navigation.</param> /// <param name="parameter">An optional command parameter or navigation target.</param> public virtual void Navigate(Uri uri, FrameworkElement source = null, string parameter = null) { if (uri == null) { throw new ArgumentNullException("uri"); } // first check if uri refers to a command ICommand command; if (Commands != null && Commands.TryGetValue(uri, out command)) { // note: not executed within BBCodeBlock context, Hyperlink instance has Command and CommandParameter set if (command.CanExecute(parameter)) { command.Execute(parameter); } } else if (uri.IsAbsoluteUri && ExternalSchemes != null && ExternalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { // uri is external, load in default browser Process.Start(uri.AbsoluteUri); } else { // perform frame navigation if (source == null) { // source required throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.NavigationFailedSourceNotSpecified, uri)); } // use optional parameter as navigation target to identify target frame (_self, _parent, _top or named target frame) ModernFrame frame = NavigationHelper.FindFrame(parameter, source); if (frame == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.NavigationFailedFrameNotFound, uri, parameter)); } // delegate navigation to the frame frame.Source = uri; } }
/// <summary> /// Performs navigation to specified link. /// </summary> /// <param name="uri">The uri to navigate to.</param> /// <param name="source">The source element that triggers the navigation. Required for frame navigation.</param> /// <param name="parameter">An optional command parameter or navigation target.</param> public virtual void Navigate(Uri uri, FrameworkElement source = null, string parameter = null) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } var args = new NavigateEventArgs(uri); PreviewNavigate?.Invoke(this, args); if (args.Cancel) { return; } // first check if uri refers to a command if (Commands != null) { ICommand command; if (Commands.TryGetValue(uri, out command)) { // note: not executed within BbCodeBlock context, Hyperlink instance has Command and CommandParameter set if (command.CanExecute(parameter)) { command.Execute(parameter); } return; } if (uri.IsAbsoluteUri) { var original = uri.AbsoluteUri; var index = original.IndexOf('?'); if (index != -1) { var subUri = new Uri(original.Substring(0, index), UriKind.Absolute); if (Commands.TryGetValue(subUri, out command)) { parameter = uri.GetQueryParam("param"); if (command.CanExecute(parameter)) { command.Execute(parameter); } return; } } } } if (uri.IsAbsoluteUri && ExternalSchemes != null && ExternalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { // uri is external, load in default browser Process.Start(uri.AbsoluteUri); } else { // perform frame navigation if (source == null) // source required { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, UiStrings.NavigationFailedSourceNotSpecified, uri)); } // use optional parameter as navigation target to identify target frame (_self, _parent, _top or named target frame) var frame = NavigationHelper.FindFrame(parameter, source); if (frame == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, UiStrings.NavigationFailedFrameNotFound, uri, parameter)); } var window = Window.GetWindow(frame) as INavigateUriHandler; if (window == null || frame.GetParent <ModernFrame>() != null || window.HandleUri(uri) != true) { // delegate navigation to the frame frame.Source = uri; } } }