/// <summary> /// Adds a new child to the stack. /// </summary> /// <param name="viewStack">The view stack.</param> /// <param name="parentViewStack">The parent view stack.</param> /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns> public bool AddChild(ViewStack viewStack, ViewStack parentViewStack) { Argument.IsNotNull("viewStack", viewStack); Argument.IsNotNull("parentViewStack", parentViewStack); if (ReferenceEquals(this, parentViewStack)) { viewStack.ViewStackLoaded += OnChildViewStackLoaded; viewStack.ViewStackUnloaded += OnChildViewStackUnloaded; viewStack.ViewLoaded += OnChildViewLoaded; viewStack.ViewUnloaded += OnChildViewUnloaded; _children.Add(viewStack); return(true); } foreach (var child in _children) { if (child.AddChild(viewStack, parentViewStack)) { return(true); } } return(false); }
/// <summary> /// Adds a new child to the stack. /// </summary> /// <param name="view">The view.</param> /// <param name="parentViewStack">The parent view stack.</param> /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns> public bool AddChild(IView view, ViewStack parentViewStack) { Argument.IsNotNull("view", view); Argument.IsNotNull("parentViewStack", parentViewStack); var viewStack = new ViewStack(view, false, parentViewStack); return(AddChild(viewStack, parentViewStack)); }
/// <summary> /// Initializes a new instance of the <see cref="ViewStack" /> class. /// </summary> /// <param name="view">The view.</param> /// <param name="isViewLoaded">if set to <c>true</c>, the view is loaded.</param> /// <param name="parentViewStack">The parent view stack. Can be <c>null</c> for root view stacks.</param> private ViewStack(IView view, bool isViewLoaded, ViewStack parentViewStack) { Argument.IsNotNull("view", view); _viewInfo = new WeakViewInfo(view, isViewLoaded); _viewInfo.Loaded += OnViewLoaded; _viewInfo.Unloaded += OnViewUnloaded; _parentViewStack = parentViewStack; if (parentViewStack != null) { _parentViewStack.ViewStackLoaded += OnParentViewStackLoaded; } }
public UninitializedViewInfo(IViewLoadState viewLoadState) { ViewLoadState = viewLoadState; ViewStack = new ViewStack(viewLoadState.View, false); }
/// <summary> /// Adds a new child to the stack. /// </summary> /// <param name="view">The view.</param> /// <param name="parentViewStack">The parent view stack.</param> /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns> public bool AddChild(IView view, ViewStack parentViewStack) { Argument.IsNotNull("view", view); Argument.IsNotNull("parentViewStack", parentViewStack); var viewStack = new ViewStack(view, false, parentViewStack); return AddChild(viewStack, parentViewStack); }
/// <summary> /// Adds a new child to the stack. /// </summary> /// <param name="viewStack">The view stack.</param> /// <param name="parentViewStack">The parent view stack.</param> /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns> public bool AddChild(ViewStack viewStack, ViewStack parentViewStack) { Argument.IsNotNull("viewStack", viewStack); Argument.IsNotNull("parentViewStack", parentViewStack); if (ReferenceEquals(this, parentViewStack)) { viewStack.ViewStackLoaded += OnChildViewStackLoaded; viewStack.ViewStackUnloaded += OnChildViewStackUnloaded; viewStack.ViewLoaded += OnChildViewLoaded; viewStack.ViewUnloaded += OnChildViewUnloaded; _children.Add(viewStack); return true; } foreach (var child in _children) { if (child.AddChild(viewStack, parentViewStack)) { return true; } } return false; }
private void AddViewAfterLoaded(UninitializedViewInfo uninitializedViewInfo) { var isTopViewStack = true; var viewLoadState = uninitializedViewInfo.ViewLoadState; var view = viewLoadState.View; ViewStack viewStack = null; var parent = view.FindParentByPredicate(x => x is IView) as FrameworkElement; if (parent != null) { if (_uninitializedViews.ContainsKey(parent)) { // We have a different uninitialized view that is the parent var uninitializedParent = _uninitializedViews[parent]; uninitializedParent.ViewStack.AddChild(uninitializedViewInfo.ViewStack, uninitializedParent.ViewStack); isTopViewStack = false; } else { // We are now listed to be added to the visual tree foreach (var existingViewStack in _viewStacks) { if (existingViewStack.ContainsView((IView)parent)) { var viewAsFrameworkElement = view as FrameworkElement; if (viewAsFrameworkElement != null && _uninitializedViews.ContainsKey(viewAsFrameworkElement)) { // This happens when we are called from OnFrameworkElementLoaded but out parent wasn't updated yet existingViewStack.AddChild(_uninitializedViews[viewAsFrameworkElement].ViewStack, existingViewStack); } else { existingViewStack.AddChild(view, existingViewStack); } viewStack = existingViewStack; isTopViewStack = false; break; } } } } if (isTopViewStack) { var topViewStack = uninitializedViewInfo.ViewStack; topViewStack.ViewStackLoaded += OnViewStackLoaded; topViewStack.ViewStackUnloaded += OnViewStackUnloaded; _viewStacks.Add(topViewStack); viewStack = topViewStack; } if (viewStack != null) { viewStack.NotifyThatParentIsReadyToAcceptLoadedMessages(); } }