private IEnumerable <ModernFrame> GetChildFrames() { var refs = this.childFrames.ToArray(); foreach (var r in refs) { var valid = false; ModernFrame frame; #if NET4 if (r.IsAlive) { frame = (ModernFrame)r.Target; #else if (r.TryGetTarget(out frame)) { #endif // check if frame is still an actual child (not the case when child is removed, but not yet garbage collected) if (NavigationHelper.FindFrame(null, frame) == this) { valid = true; yield return(frame); } } if (!valid) { this.childFrames.Remove(r); } } }
private void OnLoaded(object sender, RoutedEventArgs e) { var parent = NavigationHelper.FindFrame(NavigationHelper.FrameParent, this); if (parent != null) { parent.RegisterChildFrame(this); } }
/// <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 (this.commands != null && this.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 { // do nothing } } else if (uri.IsAbsoluteUri && this.externalSchemes != null && this.externalSchemes.Any(s => uri.Scheme.Equals(s, StringComparison.OrdinalIgnoreCase))) { // uri is external, load in default browser Process.Start(uri.AbsoluteUri); return; } 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) var 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; } }