Exemplo n.º 1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
            {
                var vm = new TweetViewModel();

                if (NavigationContext.QueryString.ContainsKey("id"))
                {
                    var id    = int.Parse(NavigationContext.QueryString["id"]);
                    var tweet = TwitterFeedManager.GetTweet(id);
                    if (tweet != null)
                    {
                        vm.Update(tweet);
                    }
                }

                if (!string.IsNullOrEmpty(vm.Content))
                {
                    //
                    // Adapt to the theme
                    //
                    var bgColor = "black";
                    var color   = "white";
                    if ((Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
                    {
                        bgColor = "white";
                        color   = "black";
                    }

                    var accentColor = (Color)Application.Current.Resources["PhoneAccentColor"];
                    var linkColor   = "#" + accentColor.ToString().Substring(3);

                    //
                    // Show the text
                    //
                    var html = string.Format("<html><head><style>body{{background-color:{0};color:{1};}} a{{color:{2};}}</style></head><body>{3}</body></html>",
                                             bgColor, color, linkColor, vm.Content);

                    Browser.NavigateToString(html);
                }

                DataContext = vm;
            }
        }