Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
                }
            }
        }
Ejemplo n.º 3
0
 /// <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)));
 }