/// <summary> /// Occurs when the navigation item has changed. /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected override void OnNavigationItemChanged(NavigationItem oldValue, NavigationItem newValue) { base.OnNavigationItemChanged(oldValue, newValue); this.SelectedItem = null; UpdateListViewStyle(); }
/// <summary> /// Invoked when this page is no longer the current page. /// </summary> /// <param name="e"></param> protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { base.OnNavigatingFrom(e); // make sure the content frame is cleared if (this.ContentFrame.SourcePageType != null && this.ContentFrame.SourcePageType != typeof(Page)) { this.ContentFrame.SourcePageType = typeof(Page); } this.ContentFrame.BackStack.Clear(); this.ContentFrame.ForwardStack.Clear(); this.lastSelectedItem = null; }
/// <summary> /// Occurs when the selected item has changed. /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected override void OnSelectedItemChanged(NavigationItem oldValue, NavigationItem newValue) { if (newValue == null || this.lastSelectedItem == newValue) { return; } this.lastSelectedItem = newValue; if (this.NavigationItem != newValue && ((!newValue.IsLeaf() || this.WindowState == WindowStateNarrow))) { // navigate to selected item base.OnSelectedItemChanged(oldValue, newValue); } else { // navigate to content and supply the PageParameter var pageType = newValue.PageType ?? typeof(Page); if (pageType != typeof(Page) || this.ContentFrame.SourcePageType != pageType) { this.ContentFrame.Navigate(pageType, newValue.PageParameter); } } }
/// <summary> /// Occurs when the navigation item has changed /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected override void OnNavigationItemChanged(NavigationItem oldValue, NavigationItem newValue) { base.OnNavigationItemChanged(oldValue, newValue); if (this.Frame == null || newValue == null) { this.SelectedItem = null; return; } string layoutStateName = LayoutStateMasterDetail; if (newValue.IsLeaf()) { // select navigation item itself this.SelectedItem = newValue; layoutStateName = LayoutStateDetail; } else if (this.SelectedItem == null) { // auto-select first child (if not set) this.SelectedItem = newValue.Items.FirstOrDefault(); } VisualStateManager.GoToState(this, layoutStateName, false); }
/// <summary> /// Occurs when the selected item has changed. /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected virtual void OnSelectedItemChanged(NavigationItem oldValue, NavigationItem newValue) { if (newValue != null) { // navigate to selected item var pageType = typeof(MasterNavigationPage); if (IsMasterDetailCandidate(newValue)) { pageType = typeof(MasterDetailNavigationPage); } this.Frame?.Navigate(pageType, newValue); } }
/// <summary> /// Occurs when the navigation item has changed /// </summary> /// <param name="oldValue"></param> /// <param name="newValue"></param> protected virtual void OnNavigationItemChanged(NavigationItem oldValue, NavigationItem newValue) { // update rootitem this.RootItem = newValue?.GetAncestorsAndSelf().LastOrDefault(); }
/// <summary> /// Determines whether specified item should be shown in the master-detail view, given the current state /// </summary> /// <param name="item"></param> /// <returns></returns> protected bool IsMasterDetailCandidate(NavigationItem item) { return !item.IsRoot() && (item.IsLeaf() || (!item.HasGrandchildren() && this.WindowState == WindowStateWide)); }
/// <summary> /// Determines whether the item is a leaf item, meaning it has no children. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool IsLeaf(this NavigationItem item) { return(service.IsLeaf(item)); }
/// <summary> /// Returns a collection of the siblings after specified item. /// </summary> /// <param name="item"></param> /// <returns></returns> public static IEnumerable <NavigationItem> GetObjectsAfterSelf(this NavigationItem item) { return(service.GetObjectsAfterSelf(item)); }
/// <summary> /// Returns a collection of items that contain the specified item and all descendant items. /// </summary> /// <param name="item"></param> /// <returns></returns> public static IEnumerable <NavigationItem> GetDescendantsAndSelf(this NavigationItem item) { return(service.GetDescendantsAndSelf(item)); }
/// <summary> /// Returns a collection of items that contain specified item, and the ancestors of specified item. /// </summary> /// <param name="item"></param> /// <returns></returns> public static IEnumerable <NavigationItem> GetAncestorsAndSelf(this NavigationItem item) { return(service.GetAncestorsAndSelf(item)); }
/// <summary> /// Determines whether the item has grandchildren. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool HasGrandchildren(this NavigationItem item) { return(service.HasGrandchildren(item)); }