/// <summary> /// Switches to the view specified. /// </summary> public async Task SwitchToAsync(View view, object data = null) { if (view == ActiveView) { return; } if (ActiveView != null) { if (SwitchMode == SwitchMode.Load) { ActiveView.Unload(); } else { ActiveView.IsActive = false; } } ActiveView = view as SceneObjectView; if (ActiveView == null) { return; } // load/activate view await ActiveView.LoadAsync(); ActiveView.IsActive = true; ActiveView.Setup(data); }
/// <summary> /// Switches to the view specified. /// </summary> public void SwitchTo(View view) { if (view == ActiveView) { return; } if (ActiveView != null) { if (SwitchMode == SwitchMode.Load) { ActiveView.Unload(); } else { ActiveView.IsActive = false; } } ActiveView = view as SceneObjectView; if (ActiveView == null) { return; } // load/activate view ActiveView.Load(); ActiveView.IsActive = true; }
/// <summary> /// Called before the view is loaded. /// </summary> protected override void BeforeLoad() { if (IgnoreObject) { return; } base.BeforeLoad(); ViewStack = new Stack <View>(); var firstChild = Content.LayoutChildren.FirstOrDefault(); // make sure load-mode is set to Manual in children if we're loading them foreach (SceneObjectView child in Content.LayoutChildren) { if (!String.IsNullOrEmpty(StartView) && child.Id.IEquals(StartView)) { ActiveView = child; continue; } if (ShowFirstByDefault && child == firstChild) { ActiveView = child; continue; } var childLoadMode = child.LoadMode | ChildLoadMode; if (SwitchMode == SwitchMode.Load || SwitchMode == SwitchMode.LoadOnce) { var loadMode = childLoadMode | LoadMode.Manual; child.LoadMode = loadMode; } else { childLoadMode &= ~LoadMode.Manual; // remove any manual flag to force automatic if we're activating them child.LoadMode = childLoadMode; if (SwitchMode == SwitchMode.Enable) { child.IsActive = false; } } } }
/// <summary> /// Called before the view is loaded. /// </summary> protected override void BeforeLoad() { if (IgnoreObject) { return; } base.BeforeLoad(); Messenger.Register <NavigatorMessage>(this, Id, OnNavigatorMessage, false, true); ViewStack = new Stack <View>(); foreach (var kv in Path.AttachedValues) { var child = kv.Key as SceneObjectView; var path = kv.Value; if (!String.IsNullOrEmpty(path) && path == StartPath) { ActiveView = child; continue; } var childLoadMode = child.LoadMode | ChildLoadMode; if (SwitchMode == SwitchMode.Load || SwitchMode == SwitchMode.LoadOnce) { var loadMode = childLoadMode | LoadMode.Manual; child.LoadMode = loadMode; } else { childLoadMode &= ~LoadMode.Manual; // remove any manual flag to force automatic if we're activating them child.LoadMode = childLoadMode; if (SwitchMode == SwitchMode.Enable) { child.IsActive = false; } } } }
/// <summary> /// Opens the page specified. /// </summary> public async void SetPageState(View view, object data, NavigationTransition navigationTransition) { if (view == ActiveView) { return; } List <Task> transitionTasks = null; SceneObjectView transitionOutView = null; if (ActiveView != null) { transitionOutView = ActiveView; transitionTasks = new List <Task>(); // add transition out task switch (navigationTransition) { case NavigationTransition.Open: transitionTasks.Add(ActiveView.SetState("Closed")); break; case NavigationTransition.Push: transitionTasks.Add(ActiveView.SetState("Pushed")); break; case NavigationTransition.Pop: transitionTasks.Add(ActiveView.SetState("Closed")); break; case NavigationTransition.Close: transitionTasks.Add(ActiveView.SetState("Closed")); break; } } ActiveView = view as SceneObjectView; if (ActiveView != null) { // load/activate view await ActiveView.LoadAsync(); ActiveView.IsActive = true; ActiveView.Setup(data); if (transitionTasks == null) { transitionTasks = new List <Task>(); } // add transition in task switch (navigationTransition) { case NavigationTransition.Push: case NavigationTransition.Open: await ActiveView.SetState("Closed", false); transitionTasks.Add(ActiveView.SetState(DefaultStateName)); break; case NavigationTransition.Pop: await ActiveView.SetState("Pushed", false); transitionTasks.Add(ActiveView.SetState(DefaultStateName)); break; default: case NavigationTransition.Close: break; } } if (transitionTasks != null) { await Task.WhenAll(transitionTasks); } // unload/deactivate views that has transitioned out if (transitionOutView != null && SwitchMode != SwitchMode.Manual) { if (SwitchMode == SwitchMode.Load) { transitionOutView.Unload(); } else { transitionOutView.IsActive = false; } } }