Наследование: GalaSoft.MvvmLight.Messaging.MessageBase
Пример #1
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="navigationParameter">The parameter value passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
 /// </param>
 /// <param name="pageState">A dictionary of state preserved by this page during an earlier
 /// session.  This will be null the first time a page is visited.</param>
 protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
 {
     if (pageState != null && pageState.ContainsKey("NavigateToUrlMessage"))
     {
         _navigateToUrlMessage = pageState["NavigateToUrlMessage"] as NavigateToUrlMessage;
         Messenger.Default.Send<NavigateToUrlMessage>(_navigateToUrlMessage);
     }
     else if (navigationParameter != null && navigationParameter is NavigateToUrlMessage)
     {
         _navigateToUrlMessage = navigationParameter as NavigateToUrlMessage;
         Messenger.Default.Send<NavigateToUrlMessage>(_navigateToUrlMessage);
     }
     RegisterShareSourceContract();
 }
Пример #2
0
 private void OnNavigateTo(NavigateToUrlMessage message)
 {
     _webViewWrapper.Url = message.TargetUrl;
     LinkedTitle = message.Title;
 }
Пример #3
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            if (pageState != null && pageState.ContainsKey("ScrollOffset"))
            {
                _scrollOffset = pageState["ScrollOffset"] as Nullable<double> ?? 0.0;

                linksView.Loaded += linksView_Loaded;
            }

            if (pageState != null && pageState.ContainsKey("SelectedSubredditMessage"))
            {
                _selectedSubredditMessage = pageState["SelectedSubredditMessage"] as SelectSubredditMessage;
                Messenger.Default.Send<SelectSubredditMessage>(_selectedSubredditMessage);
            }
            else if (navigationParameter != null)
            {
                if (navigationParameter is SelectSubredditMessage)
                {
                    _selectedSubredditMessage = navigationParameter as SelectSubredditMessage;
                    Messenger.Default.Send<SelectSubredditMessage>(_selectedSubredditMessage);
                }
                else if (navigationParameter is string)
                {
                    var navString = navigationParameter as string;
                    var thing = JsonConvert.DeserializeObject<Thing>(navString);
                    if (thing != null)
                    {
                        var link = thing.Data as Link;
                        var subreddit = thing.Data as Subreddit;

                        if (link != null)
                        {
                            var linkMessage = new NavigateToUrlMessage();
                            linkMessage.TargetUrl = link.Url;
                            linkMessage.Title = link.Title;
                            Messenger.Default.Send<NavigateToUrlMessage>(linkMessage);
                        }
                        else if (subreddit != null)
                        {
                            var selectSubreddit = new SelectSubredditMessage();
                            var typedSubreddit = new TypedThing<Subreddit>(new Thing { Kind = "t5", Data = subreddit });
                            selectSubreddit.Subreddit = new TypedThing<Subreddit>(typedSubreddit);
                            Messenger.Default.Send<SelectSubredditMessage>(selectSubreddit);
                        }
                    }
                }
            }
            else
            {
                Messenger.Default.Send<SelectSubredditMessage>(null);
            }
        }