Example #1
0
        public static Uri BuildNavigationUri(Type navPage, NavigationParameter navParam)
        {
            if (navPage == null)
                throw new ArgumentNullException("navPage");

            var queryString = String.Format("?navparam={0}", Enum.GetName(typeof(NavigationParameter), navParam));

            return new Uri(String.Format("{0}{1}.xaml{2}", AppResources.PagesLocation, navPage.Name, queryString), UriKind.Relative);
        }
        public void LoadParameters(NavigationParameter navigationParameter)
        {
            this.view.EventAggregator = navigationParameter.EventAggregator;
            this.ViewModelLocator = navigationParameter.ViewModelLocator;

            if (this.isGeneric)
            {
                this.navigationParameter = navigationParameter;
            }
        }
Example #3
0
        public static Uri BuildNavigationUri(Type navPage, NavigationParameter navParam, IDictionary<string, string> extraParams)
        {
            var resultUrl = BuildNavigationUri(navPage, navParam).ToString();
            
            foreach (var extraParam in extraParams)
            {
                resultUrl += String.Format(@"&{0}={1}", extraParam.Key, extraParam.Value);
            }

            return new Uri(resultUrl, UriKind.Relative);
        }
        /// <summary>
        /// Initializes <see cref="NavigationService"/> instance
        /// </summary>
        /// <param name="mainPageType">The type of the main application page</param>
        /// <param name="parameter">Initial navigation parameter</param>
        public void Initialize(Type mainPageType, NavigationParameter parameter)
        {
            this.mainPageType = mainPageType;
            Frame frame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active.
            if (frame == null)
            {
                logger.LogMessage("NavigationService: No root frame found. Creating the new one.");
                frame = new Frame
                {
                    CacheSize = 1,
                    Language = ApplicationLanguages.Languages[0]
                };
                Window.Current.Content = frame;
                logger.LogMessage("NavigationService: Root frame created successfully.");
            }

            if (frame.Content == null)
            {
                logger.LogMessage("NavigationService: Root frame is empty. Removing transitions for the first-time navigation.");
                if (frame.ContentTransitions != null)
                {
                    transitions = new TransitionCollection();
                    foreach (var c in frame.ContentTransitions)
                    {
                        transitions.Add(c);
                    }
                }

                frame.ContentTransitions = null;
                frame.Navigated -= onRootFrameFirstNavigated;
                frame.Navigated += onRootFrameFirstNavigated;
            }

            this.frame = frame;
            if (!frame.Navigate(mainPageType, parameter))
            {
                string message = "Navigation service initialization error.";
                logger.LogMessage(message, LoggingLevel.Critical);
                throw new Exception(message);
            }

            logger.LogMessage("NavigationService initialized.", LoggingLevel.Information);
        }
Example #5
0
 //转场检测的执行顺序为:前一个场景的退出函数->后一个场景的进入函数->转场广播
 //转场指示发出后将等待[SYSTEM]WINDOW_PAGE_CHANGE,最后触发新场景的进入完成函数
 protected override void Go_Implement(NavigationParameter e)
 {
     if (!e.PreviousScene.Scene_Exit(e.NextScene , e.ExtraData)) return;
     if (!e.NextScene.Scene_Enter(e.PreviousScene, e.ExtraData)) return;
     if (_sceneIndex != _scenes.Count - 1)
         _scenes.RemoveRange(_sceneIndex + 1, _scenes.Count - _sceneIndex + 1);
     _scenes.Add(e.NextScene);
     _sceneIndex = _scenes.Count - 1;
     _dispatcher.Invoke(() => _window.Navigate(e.NextScene.Content(), e.ExtraData));
     Core.API.Message.Wait("[SYSTEM]WINDOW_PAGE_CHANGE");
     e.NextScene.Scene_Entered(e.ExtraData);
 }
        private bool Navigate(Type type, object parameter, IViewModel viewModel)
        {
#if WINDOWSCOMMON
            if (viewModel != null)
            {
                if (!(parameter is NavigationParameter))
                    parameter = new NavigationParameter { Id = viewModel.GetViewModelId(), Parameter = parameter };
            }
#endif
            _lastParameter = parameter;
            if (parameter == null)
                return _frame.Navigate(type);
            return _frame.Navigate(type, parameter);
        }
        /// <summary>
        /// Navigates to the main application page with passing given parameter to it
        /// </summary>
        /// <param name="parameter">Navigation parameter to pass</param>
        public void Navigate(NavigationParameter parameter)
        {
            if (!isInitialized)
            {
                logger.LogMessage($"NavigationService: Root frame hasn't initialized yet. Schedule navigation with parameter {parameter}.");
                deferredNavigationHandler = (_, __) =>
                {
                    logger.LogMessage("NavigationService: Executing deferred navigation handler.");
                    frame.LayoutUpdated -= deferredNavigationHandler;
                    Navigate(parameter);
                };
                return;
            }

            logger.LogMessage($"NavigationService: Navigating with parameter {parameter}.");

            if (!frame.Navigate(mainPageType, parameter))
            {
                logger.LogMessage("Navigation error.", LoggingLevel.Error);
            }
        }
Example #8
0
 internal void LoadNavigationParameter(NavigationParameter parameter)
 {
     this.NavigationService = parameter.NavigationService;
     this.EventAggregator = parameter.EventAggregator;
     this.LoadChildsNavigationParameter(parameter);
 }
Example #9
0
 private void LoadChildsNavigationParameter(NavigationParameter parameter)
 {
     ForEachChildViewModels(this, vm => {
         var viewModel = vm as ViewModel;
         if (viewModel != null)
         {
             viewModel.LoadNavigationParameter(parameter);
         }
     });
 }
Example #10
0
 public static void NavigateTo(Type navPage, NavigationParameter navParam)
 {
     ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(BuildNavigationUri(navPage, navParam));
 }
Example #11
0
 public static void NavigateTo(Type navPage, NavigationParameter navParam, IDictionary<string, string> extraParams)
 {
     ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(BuildNavigationUri(navPage, navParam, extraParams));
 }
        private void listView_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var _listview = listView as ListView;
            var _weibo = (Weibo)_listview.SelectedItem;
            ListViewItemPresenter originalsource = e.OriginalSource as ListViewItemPresenter;
            if (originalsource == null)
            {
                var advancesource = e.OriginalSource as TextBlock;
                var imageSource = e.OriginalSource as Image;
                var richtextBlock = e.OriginalSource as RichTextBlock;
                if (advancesource != null)
                {
                    if (advancesource.Text == "网页链接")
                    {
                        e.Handled = true;
                    }
                    else if (advancesource.Text.Substring(0, 1) == "#")
                    {
                        string hashtag = advancesource.Text.Substring(1);
                        hashtag = hashtag.Remove(hashtag.Length - 1);
                        //Frame.Navigate(typeof(HashTagPage), hashtag);
                    }
                    else if (advancesource.Text.Substring(0, 1) == "@")
                    {
                        string username = advancesource.Text.Substring(1);
                        NavigationParameter navip = new NavigationParameter(username, "screen_name");
                        Frame.Navigate(typeof(UserView), navip);
                    }
                    else if (_weibo.User.ScreenName != null && advancesource.Text == _weibo.User.ScreenName)
                    {
                        string username = advancesource.Text;
                        NavigationParameter navip = new NavigationParameter(username, "screen_name");
                        Frame.Navigate(typeof(UserView), navip);
                    }
                    else if(advancesource.Text == _weibo.RepostWeibo.User.ScreenName)
                    {
                        string username = advancesource.Text;
                        NavigationParameter navip = new NavigationParameter(username, "screen_name");
                        Frame.Navigate(typeof(UserView), navip);
                    }
                    else
                    {
                        Frame.Navigate(typeof(WeiboDetailView), _weibo);
                    }
                }

                else if (imageSource != null)
                {
                    string username = _weibo.User.ScreenName;
                    NavigationParameter navip = new NavigationParameter(username, "screen_name");
                    Frame.Navigate(typeof(UserView), navip);
                }
                else if (richtextBlock != null)
                {
                    Frame.Navigate(typeof(WeiboDetailView), _weibo);
                }
            }

            else
            {
                Frame.Navigate(typeof(WeiboDetailView), _weibo);
            }
        }