Example #1
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> that is passed to the action by the behavior. Generally this is <seealso cref="Microsoft.Xaml.Interactivity.IBehavior.AssociatedObject"/> or a target object.</param>
        /// <param name="parameter">The value of this parameter is determined by the caller.</param>
        /// <returns>True if the navigation to the specified page is successful; else false.</returns>
        public object Execute(object sender, object parameter)
        {
            if (string.IsNullOrEmpty(this.TargetPage))
            {
                return(false);
            }

            IXamlMetadataProvider metadataProvider = Application.Current as IXamlMetadataProvider;

            if (metadataProvider == null)
            {
                // This will happen if there are no XAML files in the project other than App.xaml.
                // The markup compiler doesn't bother implementing IXamlMetadataProvider on the app
                // in that case.
                return(false);
            }

            IXamlType xamlType = metadataProvider.GetXamlType(this.TargetPage);

            if (xamlType == null)
            {
                return(false);
            }

            INavigate        navigateElement = Window.Current.Content as INavigate;
            DependencyObject senderObject    = sender as DependencyObject;

            // If the sender wasn't an INavigate, then keep looking up the tree from the
            // root we were given for another INavigate.
            while (senderObject != null && navigateElement == null)
            {
                navigateElement = senderObject as INavigate;
                if (navigateElement == null)
                {
                    senderObject = this._visualTreeHelper.GetParent(senderObject);
                }
            }

            if (navigateElement == null)
            {
                return(false);
            }

            Frame frame = navigateElement as Frame;

            if (frame != null)
            {
                return(frame.Navigate(xamlType.UnderlyingType, this.Parameter ?? parameter));
            }
            else
            {
                return(navigateElement.Navigate(xamlType.UnderlyingType));
            }
        }
Example #2
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> that is passed to the action by the behavior. Generally this is <seealso cref="Microsoft.Xaml.Interactivity.IBehavior.AssociatedObject"/> or a target object.</param>
        /// <param name="parameter">The value of this parameter is determined by the caller.</param>
        /// <returns>True if the navigation to the specified page is successful; else false.</returns>
        public object Execute(object sender, object parameter)
        {
            if (string.IsNullOrEmpty(this.TargetPage))
            {
                return(false);
            }

            IXamlMetadataProvider metadataProvider = (IXamlMetadataProvider)Application.Current;
            IXamlType             xamlType         = metadataProvider.GetXamlType(this.TargetPage);

            if (xamlType == null)
            {
                return(false);
            }

            INavigate        navigateElement = Window.Current.Content as INavigate;
            DependencyObject senderObject    = sender as DependencyObject;

            // If the sender wasn't an INavigate, then keep looking up the tree from the
            // root we were given for another INavigate.
            while (senderObject != null && navigateElement == null)
            {
                navigateElement = sender as INavigate;
                if (navigateElement == null)
                {
                    senderObject = VisualTreeHelper.GetParent(senderObject);
                }
            }

            if (navigateElement == null)
            {
                return(false);
            }

            Frame frame = navigateElement as Frame;

            if (frame != null)
            {
                return(frame.Navigate(xamlType.UnderlyingType, this.Parameter ?? parameter));
            }
            else
            {
                return(navigateElement.Navigate(xamlType.UnderlyingType));
            }
        }
Example #3
0
        public object Execute(object sender, object parameter)
        {
            if (null == Page)
            {
                return(false);
            }

            if (Frame == null)
            {
                throw new NullReferenceException($"{nameof(NavToPageAction)}.{nameof(Frame)} is required.");
            }


            var navs = Locator.WindowWrapper.Instances.SelectMany(x => x.NavigationServices);
            var nav  = navs.First(x => (x.FrameFacade as IFrameFacadeInternal).Frame == Frame);

            if (nav == null)
            {
                throw new NullReferenceException($"Cannot find NavigationService for {Frame.ToString()}.");
            }

            IXamlMetadataProvider metadataProvider = Application.Current as IXamlMetadataProvider;

            if (metadataProvider == null)
            {
                throw new Exception($"1 Cannot find type {Page}");
            }
            IXamlType xamlType = metadataProvider.GetXamlType(Page);

            if (xamlType == null)
            {
                throw new Exception($"2 Cannot find type {Page}");
            }
            Type type = xamlType.UnderlyingType;

            if (type == null)
            {
                throw new Exception($"3 Cannot find type {Page}");
            }
            nav.Navigate(type, Parameter, InfoOverride);
            return(null);
        }
Example #4
0
        public object Execute(object sender, object parameter)
        {
            if (null == Page)
            {
                return(false);
            }

            if (Frame == null)
            {
                throw new NullReferenceException($"{nameof(NavToPageAction)}.{nameof(Frame)} is required.");
            }


            var nav = NavigationService.GetForFrame(Frame);

            if (nav == null)
            {
                throw new NullReferenceException($"Cannot find NavigationService for {Frame.ToString()}.");
            }

            IXamlMetadataProvider metadataProvider = Application.Current as IXamlMetadataProvider;

            if (metadataProvider == null)
            {
                throw new Exception($"1 Cannot find type {Page}");
            }
            IXamlType xamlType = metadataProvider.GetXamlType(Page);

            if (xamlType == null)
            {
                throw new Exception($"2 Cannot find type {Page}");
            }
            Type type = xamlType.UnderlyingType;

            if (type == null)
            {
                throw new Exception($"3 Cannot find type {Page}");
            }
            nav.Navigate(type, Parameter, InfoOverride);
            return(null);
        }