Inheritance: Windows.UI.Xaml.Controls.Primitives.ButtonBase, IHyperlinkButton
        public static void OnTextContent(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var richText = (RichTextBlock)d;
            var textContent = (string)e.NewValue;

            richText.Blocks.Clear();

            if(string.IsNullOrEmpty(textContent)) {
                return;
            }
            var paragraph = new Paragraph();
            richText.Blocks.Add(paragraph);

            var matches = UrlRegex.Matches(textContent);
            if(matches.Count == 0) {
                paragraph.Inlines.Add(new Run { Text = textContent });
                return;
            }
            int index = 0;
            foreach(Match match in matches) {
                Uri uri = null;
                Uri.TryCreate(match.Value, UriKind.Absolute, out uri);
                if(match.Index > 0) {
                    var length = match.Index - index;
                    if(length > 0) {
                        paragraph.Inlines.Add(new Run { Text = textContent.Substring(index, length) });
                    }
                }

                var underline = new Underline();
                underline.Inlines.Add(new Run { Text = uri.Host });
                var linkContent = new TextBlock();
                linkContent.Inlines.Add(underline);
                var hyperlink = new HyperlinkButton {
                    NavigateUri = uri,
                    Content = linkContent,
                    Style = (Style)Application.Current.Resources["TextButtonStyle"],
                    Margin = new Thickness(0, 0, 0, -4)
                };
                paragraph.Inlines.Add(
                    new InlineUIContainer {
                        Child = hyperlink
                    });
                index = match.Index + match.Length;
            }
            if(index < textContent.Length - 1) {
                var lastRunText = textContent.Substring(index);
                if(lastRunText.Length > 0) {
                    paragraph.Inlines.Add(new Run { Text = lastRunText });
                }
            }
        }
        private static void TextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) {
            var hyperlink = (Hyperlink)dependencyObject;
            hyperlink.Inlines.Clear();

            var link = new HyperlinkButton {
                Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0x63, 0xA0, 0xD0)),
                Margin = new Thickness(-3, 0, -3, -7),
                Padding = new Thickness(0),
                Content = args.NewValue,
                FontSize = hyperlink.FontSize
            };
            link.Tapped += delegate { hyperlink.TriggerLink(true); };
            link.RightTapped += delegate { hyperlink.TriggerLink(false); };
            hyperlink.marker = new InlineUIContainer { Child = link };
            hyperlink.Inlines.Add(hyperlink.marker);
        }
		public async void ShowMessageDialog(DialogMessage message)
		{
			using (await ALocker.LockAsync())
			{
				callback = null;
				if (message.Description != null && message.Title != null)
				{
					Title = message.Title;
					Body.Text = message.Description;
				}
				else
				{
					Title = "";
					Body.Text = message.Description;
				}

				LinkContainer.Children.Clear();
				if (message.Buttons != null && message.Buttons.Count > 0)
				{
					IsPrimaryButtonEnabled = false;
					foreach (var b in message.Buttons)
					{
						HyperlinkButton button = new HyperlinkButton();
						button.Content = b.Text;
						button.Tag = b.Id;
						button.Tapped += Button_Tapped;
						LinkContainer.Children.Add(button);
					}
				}
				else
				{
					IsPrimaryButtonEnabled = true;
					PrimaryButtonText = "Ok";
				}

				if (message.CallBack != null)
				{
					callback = message.CallBack;
				}



				await ShowAsync();
			}
		}
 public void AddLine(string mainLine, string extraString = null)
 {
     if (extraString != null)
     {
         var stack = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Stretch};
         foreach (var elem in SplitLine(extraString))
         {
             if (elem[0] == ' ')
             {
                 stack.Children.Add(new HyperlinkButton()
                 {
                     Content = new string('_', elem.Length),
                     FontSize = 18,
                     Opacity = 0
                 });
             }
             else
             {
                 var hl = new HyperlinkButton()
                 {
                     Content = elem,
                     FontSize = 20,
                     FontWeight = FontWeights.ExtraBold,
                     Foreground = new SolidColorBrush(Colors.Maroon)
                 };
                 hl.Click += Hl_Click;
                 stack.Children.Add(hl);
             }
         }
         Panel.Children.Add(stack);
     }
     Panel.Children.Add(new TextBlock()
     {
         Text = mainLine,
         FontSize = 18,
         Foreground = new SolidColorBrush(Colors.Black),
         HorizontalAlignment = HorizontalAlignment.Stretch
     });
 }
Beispiel #5
0
            protected override void OnApplyTemplate()
            {
                Debug.Assert((m_scrollLeft == null && m_scrollRight == null) || (m_scrollLeft != null && m_scrollRight != null));
                if (m_textContainer != null)
                {
                    // UNO TODO
                    // m_textContainer.LayoutUpdated -= m_textContainerLayoutChangedToken;
                }
                m_textContainer = (ScrollViewer)(GetTemplateChild("TextContainer"));
                if (m_textContainer != null)
                {
                    m_textContainer.SizeChanged += TextContainerSizeChanged;
                    // We want to know when the size of the container changes so
                    // we can rescale the textbox
                    m_textContainer.LayoutUpdated += OnTextContainerLayoutUpdated;

                    m_textContainer.ChangeView(m_textContainer.ExtentWidth - m_textContainer.ViewportWidth, null, null);
                    m_scrollLeft  = (HyperlinkButton)(GetTemplateChild("ScrollLeft"));
                    m_scrollRight = (HyperlinkButton)(GetTemplateChild("ScrollRight"));
                    var borderContainer = (UIElement)(GetTemplateChild("Border"));
                    if (m_scrollLeft != null && m_scrollRight != null)
                    {
                        m_scrollLeft.Click             += OnScrollClick;
                        m_scrollRight.Click            += OnScrollClick;
                        borderContainer.PointerEntered += OnPointerEntered;
                        borderContainer.PointerExited  += OnPointerExited;
                    }
                    m_textBlock = (TextBlock)(m_textContainer.FindName("NormalOutput"));
                    if (m_textBlock != null)
                    {
                        m_textBlock.Visibility = Visibility.Visible;
                    }
                }
                UpdateAllState();
                VisualStateManager.GoToState(this, s_UnfocusedState, false);
            }
        private static List<Inline> CreateInlineCollection(string newValue)
        {
            var inlines = new List<Inline>();
            bool bold = false;
            bool list_item = false;
            bool unordered_list = false;
            bool ordered_list = false;
            string href = "";
            int ordered_number = -1;
            int linebreak_count = 0;
            var splits = Regex.Split(newValue, htmlLineBreakRegex, RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
            foreach (var line in splits)
            {
                if (string.IsNullOrWhiteSpace(line)) continue;
                var line_lowercase = line.ToLower();
                if (IsHtmlTag(line_lowercase))
                {
                    switch (line_lowercase)
                    {
                        case "</div>":
                        case "</p>":
                        case "<br/>":
                        case "<br />":
                        case "<br>":
                            if (!ordered_list && !unordered_list)
                                WriteLineBreak(inlines, ref linebreak_count);
                            break;
                        case "<bold>":
                        case "<b>":
                            bold = true;
                            break;
                        case "</bold>":
                        case "</b>":
                            bold = false;
                            break;
                        case "<ul>":
                            WriteLineBreak(inlines, ref linebreak_count);
                            unordered_list = true;
                            break;
                        case "</ul>":
                            unordered_list = false;
                            break;
                        case "<ol>":
                            WriteLineBreak(inlines, ref linebreak_count);
                            ordered_list = true;
                            ordered_number = 1;
                            break;
                        case "</ol>":
                            ordered_list = false;
                            ordered_number = -1;
                            break;
                        case "<li>":
                            list_item = true;
                            break;
                        case "</li>":
                            list_item = false;
                            WriteLineBreak(inlines, ref linebreak_count);
                            break;
                        case "</a>":
                            href = "";
                            break;
                    }
                }

                if (line_lowercase == "<p>" || (line_lowercase.StartsWith("<p ") && line_lowercase.EndsWith(">")))
                {
                    if (!ordered_list && !unordered_list)
                        WriteLineBreak(inlines, ref linebreak_count);
                }

                if (line_lowercase.StartsWith("<a ") && line_lowercase.Contains("href="))
                {
                    char quote = line_lowercase.Contains("href='") ? '\'' : '"';
                    int start_index = line_lowercase.IndexOf(string.Format("href={0}", quote)) + 6;
                    int end_index = line_lowercase.IndexOf(string.Format("{0}", quote), start_index);
                    href = line.Substring(start_index, end_index - start_index);
                }

                if (line_lowercase.StartsWith("<img") && line_lowercase.Contains("src='"))
                {
                    int start_index = line_lowercase.IndexOf("src='") + 5;
                    int end_index = line.IndexOf("'", start_index);
                    string src = line.Substring(start_index, end_index - start_index);

                    var image = new Image() { Source = new BitmapImage(new Uri(src, UriKind.Absolute)) };
                    image.Stretch = Stretch.None;

                    var inline_ui_container = new InlineUIContainer();
                    inline_ui_container.Child = image;

                    inlines.Add(inline_ui_container);
                    WriteLineBreak(inlines, ref linebreak_count);
                    WriteLineBreak(inlines, ref linebreak_count);
                }

                string text = Regex.Replace(line, htmlStripperRegex, string.Empty);
                Regex regex = new Regex(@"[ ]{2,}", RegexOptions.None);
                if (!string.IsNullOrWhiteSpace(text))
                {
                    text = regex.Replace(text, @" "); //Remove multiple spaces
                    text = text.Replace("&quot;", "\""); //Unencode quotes
                    text = text.Replace("&nbsp;", " "); //Unencode spaces
                    var run = new Run() { Text = text };

                    if (bold)
                        run.FontWeight = FontWeights.SemiBold;

                    if (unordered_list && list_item)
                    {
                        run.Text = run.Text.Insert(0, "•  ");
                        list_item = false;
                    }

                    if (ordered_list && list_item)
                    {
                        run.Text = run.Text.Insert(0, string.Format("{0}.  ", ordered_number++));
                        list_item = false;
                    }

                    if (!string.IsNullOrEmpty(href))
                    {
                        int pos = 0;
                        foreach (var str in text.Split(new char[] { ' ', '/' }))
                        {
                            var word = str;
                            pos += word.Length;
                            if (pos < text.Length)
                            {
                                word += text[pos];
                                pos++;
                            }
                            var hyperlink = new HyperlinkButton();
                            hyperlink.NavigateUri = new Uri(href, UriKind.Absolute);
                            hyperlink.Content = word;
                            hyperlink.Template = (ControlTemplate)XamlReader.Load(
                                "<ControlTemplate TargetType='HyperlinkButton' xmlns='http://schemas.microsoft.com/client/2007' >" +
                                "<TextBlock Text='{TemplateBinding Content}' Padding='0' Margin='0' RenderTransformOrigin='0.5,0.5'>" +
                                "<TextBlock.RenderTransform>" +
                                "<CompositeTransform TranslateY='5' />" +
                                "</TextBlock.RenderTransform>" +
                                "</TextBlock>" +
                                "</ControlTemplate>");
                            hyperlink.FontFamily = new FontFamily("Segoe UI Light");
                            hyperlink.FontWeight = FontWeights.Normal;
                            hyperlink.Margin = new Thickness(0);
                            if (word.EndsWith(" "))
                                hyperlink.Margin = new Thickness(0, 0, 4, 0);
                            hyperlink.Padding = new Thickness(0);
                            var inline_ui_container = new InlineUIContainer();
                            inline_ui_container.Child = hyperlink;

                            inlines.Add(inline_ui_container);
                        }
                    }
                    else
                        inlines.Add(run);

                    linebreak_count = 0;
                }
            }
            return inlines;
        }
        /// <summary>
        /// Appends a HyperlinkButton with
        /// the given text and navigate uri to the given RichTextBlock.
        /// </summary>
        /// <param name="richTextBlock">The rich text block.</param>
        /// <param name="text">The text.</param>
        /// <param name="uri">The URI.</param>
        public static void AppendLink(this RichTextBlock richTextBlock, string text, Uri uri)
        {
            Paragraph paragraph;

            if (richTextBlock.Blocks.Count == 0 ||
                (paragraph = richTextBlock.Blocks[richTextBlock.Blocks.Count - 1] as Paragraph) == null)
            {
                paragraph = new Paragraph();
                richTextBlock.Blocks.Add(paragraph);
            }

            var link =
                new HyperlinkButton
                {
                    Content = text,
                    NavigateUri = uri
                };

            paragraph.Inlines.Add(new InlineUIContainer { Child = link });
        }
Beispiel #8
0
 async void MainPage_Load(object sender, RoutedEventArgs e)
 {
     Files.Items.Clear();
    
     //获取应用程序的本地存储文件NoteList
     StorageFolder storage = await ApplicationData.Current.LocalFolder.CreateFolderAsync("NoteList", CreationCollisionOption.OpenIfExists);
     //获取当前文件夹的文件
     var files = await storage.GetFilesAsync();
     {
         //便利 获取所有文件
         foreach (StorageFile file in files)
         {
             //初始化一个Grid类
             Grid a = new Grid();
             //列的属性
             ColumnDefinition col = new ColumnDefinition();
             //宽度200
             GridLength gl = new GridLength(200);
             col.Width = gl;
             //添加col
             a.ColumnDefinitions.Add(col);
             //定义第二列
             ColumnDefinition col2 = new ColumnDefinition();
             GridLength gl2 = new GridLength(100);
             col2.Width = gl2;//////////////
             a.ColumnDefinitions.Add(col2);
             //定义第三列
             ColumnDefinition col3 = new ColumnDefinition();
             GridLength g13 = new GridLength(100);
             col3.Width = g13;
             a.ColumnDefinitions.Add(col3);
             //添加一个TextBlock显示记事本名到第一列
             TextBlock txbx = new TextBlock();
             txbx.Text = file.DisplayName;
             txbx.FontSize = 20;
             //把txbx设置到Grid 0号位置
             Grid.SetColumn(txbx, 0);
             //添加一个HyperlinkButton链接到记事本页面,这是第二列
             //HyperlinkButton 可跳转Button
             HyperlinkButton btn = new HyperlinkButton();
             btn.Width = 80;
             btn.Content = "删除";
             btn.Foreground  = new SolidColorBrush(Colors.Blue );
             btn.FontSize = 20;
             btn.Name = file.DisplayName;
             //Lambda表达式
             //事件添加一个Lambda表达式
             //等价于下面btn_Click方法
             btn.Click += (s ,ea) =>
                 {
                     Frame.Navigate(typeof(DeleteItem ),file );
                 };
             Grid.SetColumn(btn ,1);
             //添加一个HyperlinkButton链接到记事本页面,这是第三列
             HyperlinkButton btn1 = new HyperlinkButton();
             btn1.Width = 80;
             btn1.Content = "打开";
             btn1.FontSize = 20;
             btn1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
             btn1.Name = file.DisplayName;
             btn1.Click += (s, ea) =>
             {
                 Frame.Navigate(typeof(AddItem), file);
             };
             Grid.SetColumn(btn1, 2);
             //给Grid a 添加子元素
             a.Children.Add(txbx);
             a.Children.Add(btn);
             a.Children.Add(btn1);
             //将 a 添加到Files中
             Files.Items.Add(a);
         }
     }
 }
        // 依存関係プロパティに値がセットされたときに呼び出されるメソッド
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBlock block = new RichTextBlock();
            Tweet tweet = e.NewValue as Tweet;
            Binding detailCommandBinding = new Binding { Path = new PropertyPath("TweetDetailCommand") };

            Binding userDetailCommandBinding = new Binding { Path = new PropertyPath("UserDetailCommand") };

            Binding searchCommandBinding = new Binding() { Path = new PropertyPath("SearchCommand") };

            Binding browseCommandBinding = new Binding() { Path = new PropertyPath("BrowseCommand") };

            Binding previewImageCommandBinding = new Binding() { Path = new PropertyPath("ImagePreviewCommand") };



                SolidColorBrush runForeGround = Application.Current.Resources["ForegroundBrush"] as SolidColorBrush;
                FontFamily tweetFontFamily = Application.Current.Resources["MainFontFamily"] as FontFamily;
                double fontSize = (double)Application.Current.Resources["TimelineFontSize"];
                if (tweet != null)
                {



                    if (tweet.retweeted_status != null)
                    {
                        tweet = tweet.retweeted_status;
                    }

                    
                    Paragraph para = new Paragraph();

                    List<EntitieBase> entities = new List<EntitieBase>();
                    if (tweet.entities != null)
                    {

                        if (tweet.entities.user_mentions != null)
                        {
                            entities.AddRange(tweet.entities.user_mentions);
                        }
                        if (tweet.entities.urls != null)
                        {
                            entities.AddRange(tweet.entities.urls);
                        }
                        if (tweet.entities.hashtags != null)
                        {
                            entities.AddRange(tweet.entities.hashtags);
                        }
                        if (tweet.entities.media != null)
                        {
                            entities.AddRange(tweet.entities.media);
                        }
                    }


                    try
                    {
                        if (tweet.entities != null && entities.Count > 0)
                        {

                            entities.OrderBy(q => q.indices[0]);
                            string back = "";
                            int seek = 0;


                            foreach (EntitieBase entitiy in entities)
                            {

                                int start = entitiy.indices[0];
                                int end = entitiy.indices[1];
                                StringInfo infoText = new StringInfo(tweet.text);
                                back = tweet.text.SubStringByTextElements(end, infoText.LengthInTextElements - end);
                                string front = tweet.text.SubStringByTextElements(seek, start - seek);

                                para.Inlines.Add(new Run { Text = front, Foreground = runForeGround, FontSize = fontSize });
                                var link = new HyperlinkButton();
                                link.Padding = new Thickness(0);
                                // link.Foreground = Application.Current.Resources["AppThemeBrush"] as SolidColorBrush;
                                link.Style = Application.Current.Resources["NeuroniaTimelineHyperlinkButtonStyle"] as Style;
                                link.FontSize = fontSize;

                                var uiContainer = new InlineUIContainer();

                                if (entitiy is UserMention)
                                {
                                    var en = entitiy as UserMention;

                                    link.Content = "@" + en.screen_name;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.screen_name;
                                    link.SetBinding(HyperlinkButton.CommandProperty, userDetailCommandBinding);
                                }
                                else if (entitiy is TweetUrl)
                                {
                                    var en = entitiy as TweetUrl;
                                    link.Content = en.display_url;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.url;
                                    link.SetBinding(HyperlinkButton.CommandProperty, browseCommandBinding);

                                }
                                else if (entitiy is HashTag)
                                {
                                    var en = entitiy as HashTag;
                                    link.Content = "#" + en.text;
                                    uiContainer.Child = link;
                                    link.CommandParameter = "#" + en.text;
                                    link.SetBinding(HyperlinkButton.CommandProperty, searchCommandBinding);
                                }
                                else if (entitiy is TweetMedia)
                                {
                                    var en = entitiy as TweetMedia;

                                    Button btn = new Button();
                                    btn.Width = (double)Application.Current.Resources["previewImageWidth"];

                                    //btn.HorizontalAlignment = HorizontalAlignment.Stretch;
                                    btn.Height = (double)Application.Current.Resources["previewImageHeight"];
                                    btn.Style = Application.Current.Resources["NeuroniaTimelineImageButtonStyle"] as Style;
                                    var imageBrush = new ImageBrush() { ImageSource = new BitmapImage(new Uri(en.media_url)), Stretch = Stretch.UniformToFill };
                                    btn.Background = imageBrush;
                                    btn.CommandParameter = en;
                                    btn.SetBinding(Button.CommandProperty, previewImageCommandBinding);
                                    var flyout = Application.Current.Resources["ImagePreviewFlyout"] as Flyout;
                                    flyout.Placement = FlyoutPlacementMode.Top;

                                    var grid = (flyout.Content as Grid);

                                    btn.Flyout = flyout;
                                    uiContainer.Child = btn;

                                    para.Inlines.Add(new LineBreak());
                                }
                                para.Inlines.Add(uiContainer);
                                seek = end;
                            }

                            para.Inlines.Add(new Run { Text = back, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });


                        }
                        else
                        {
                            para.Inlines.Add(new Run { Text = tweet.text, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });
                        }

                        block.Blocks.Add(para);
                    }
                    catch (Exception ee)
                    {
                        //Debug.WriteLine(value.ToString());
                    }

                    
                }
            

            (d as ContentControl).Content = block;

            
            
        }
        private static Inline GenerateHyperLink(HtmlNode node)
        {
            Span s = new Span();
            InlineUIContainer iui = new InlineUIContainer();
            HyperlinkButton hb = new HyperlinkButton() { NavigateUri = new Uri(node.Attributes["href"].Value, UriKind.Absolute), Content = CleanText(node.InnerText) };

            if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI"))
                hb.Style = (Style)Application.Current.Resources["RTLinkLI"];
            else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText)))
                hb.Style = (Style)Application.Current.Resources["RTLinkOnly"];
            else
                hb.Style = (Style)Application.Current.Resources["RTLink"];

            iui.Child = hb;
            s.Inlines.Add(iui);
            return s;
        }
Beispiel #11
0
        public void AboutPane()
        {
            ResourceLoader resourceLoader = new ResourceLoader();
            StackPanel s = new StackPanel();
            s.Orientation = Orientation.Vertical;
            HyperlinkButton aheadLink = new HyperlinkButton();
            HyperlinkButton policy = new HyperlinkButton();

            Image aheadLogo = new Image();
            aheadLogo.Source = new BitmapImage(new Uri("ms-appx:/Content/Images/logo_ahead.png", UriKind.RelativeOrAbsolute));
            aheadLogo.Width = 160;


            TextBlock t1 = new TextBlock() { TextWrapping = TextWrapping.Wrap };
            TextBlock t2 = new TextBlock() { TextWrapping = TextWrapping.Wrap };
            TextBlock t2_click = new TextBlock() { TextWrapping = TextWrapping.Wrap };
            TextBlock t3 = new TextBlock() { TextWrapping = TextWrapping.Wrap };


            t1.Text = resourceLoader.GetString("TitleMyThings");
            t1.Margin = new Thickness(4);
            t1.FontSize = 16;
            t1.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            t1.Foreground = new SolidColorBrush(Colors.Black);

            StackPanel sText = new StackPanel();
            sText.Orientation = Orientation.Horizontal;
            sText.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            sText.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;



            t2.Text = "© 2012";
            t2.FontSize = 16;
            t2.Foreground = new SolidColorBrush(Colors.Black);
            t2.TextAlignment = TextAlignment.Right;
            t2.Foreground = new SolidColorBrush(Colors.Black);
            t2.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;

            aheadLink.Foreground = new SolidColorBrush(Colors.Black);
            aheadLink.Click += new RoutedEventHandler(GoToAheadSolutions);
            aheadLink.BorderBrush = new SolidColorBrush(Colors.Transparent);
            aheadLink.Content = "Ahead Solutions";
            aheadLink.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
            aheadLink.Margin = new Thickness(0, 0, 0, 3);



            StackPanel sText2 = new StackPanel();
            sText2.Orientation = Orientation.Horizontal;
            sText2.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            sText2.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch;

            policy.Foreground = new SolidColorBrush(Colors.Black);
            policy.Click += new RoutedEventHandler(GoToPolicy);
            policy.BorderBrush = new SolidColorBrush(Colors.Transparent);
            policy.Content = "Politique de confidentialité";
            policy.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch;
            policy.Margin = new Thickness(0, 0, 0, 3);


            sText.Children.Add(t2);
            sText.Children.Add(aheadLink);

            sText2.Children.Add(policy);

            t3.Text = resourceLoader.GetString("TextDescriMyThings");
            t3.Margin = new Thickness(10);
            t3.FontSize = 16;
            t3.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            t3.Foreground = new SolidColorBrush(Colors.Black);

            s.Children.Add(aheadLogo);
            s.Children.Add(t1);
            s.Children.Add(sText);
            s.Children.Add(sText2);
            s.Children.Add(t3);


            FlyoutCharm f = new FlyoutCharm(
                new SolidColorBrush(Colors.Black),
                new SolidColorBrush(Colors.White),
                "About",
                FlyoutDimension.Narrow,
                s);
            f.Show();
        }
 private void Hl_Click(object sender, RoutedEventArgs e)
 {
     clickedButton = (HyperlinkButton) sender;
     var accordText = (string)clickedButton.Content;
     accordDialog.SetAccord(clickedButton.Content.ToString());
     accordDialog.ShowAsync();
 }
Beispiel #13
0
        private static StackPanel GetPhonesPanel(IEnumerable<Phone> phones)
        {
            var phonesPanel = new StackPanel();

            foreach (Phone phone in phones)
            {
                TextBlock hyperlinkText = LayoutObjectFactory.CreateTextBlock(phone.FormattedPhone);
                hyperlinkText.FontSize = 18;
                hyperlinkText.TextWrapping = TextWrapping.Wrap;
                hyperlinkText.HorizontalAlignment = HorizontalAlignment.Left;
                hyperlinkText.VerticalAlignment = VerticalAlignment.Top;
                hyperlinkText.Margin = new Thickness(10, 0, 0, 0);
                hyperlinkText.Width = Window.Current.Bounds.Width - 160 - 40;

                var button = new HyperlinkButton
                {
                    Foreground = LayoutObjectFactory.GetThemeColor(),
                    Content = hyperlinkText,
                    Tag = phone.PhoneNumber,
                    CommandParameter = phone.DisplayName,
                };
                button.Click += MakeCall;

                phonesPanel.Children.Add(button);
            }

            return phonesPanel;
        }
        private static void ParseElement(XmlElement element, ITextContainer parent)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    parent.Add(new Run { Text = child.InnerText.Trim(new char[] {'\n'}) });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "P":
                            var paragraph = new Paragraph();
                            parent.Add(paragraph);
                            ParseElement(e, new ParagraphTextContainer(paragraph));
                            break;
                        case "STRONG":
                            var bold = new Bold();
                            parent.Add(bold);
                            ParseElement(e, new SpanTextContainer(bold));
                            break;
                        case "U":
                            var underline = new Underline();
                            parent.Add(underline);
                            ParseElement(e, new SpanTextContainer(underline));
                            break;
                        case "A":
                            var inlineElt = new InlineUIContainer();
                            var hyperlink = new HyperlinkButton();
                            inlineElt.Child = hyperlink;
                            hyperlink.Style = (Style)App.Current.Resources["HyperlinkButtonStyle"];
                            hyperlink.Content = e.InnerText;
                            hyperlink.Click += delegate(object sender, RoutedEventArgs eventArgs)
                            {
                                string uriString = e.GetAttribute("href");
                                Messenger.Default.Send<LinkClickedMessage>(new LinkClickedMessage()
                                {
                                    UriToNavigate = uriString
                                });
                            };
                            parent.Add(inlineElt);
                            //ParseElement(e, parent);
                            break;
                        case "BR":
                                parent.Add(new LineBreak());
                            break;
                    }
                }

            }
        }
        private void UpdateTemplate()
        {
            var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            Content = stackPanel;

            var titleText = new TextBlock
            {
                Style = _pageSubHeaderTextStyle,
                TextWrapping = TextWrapping.Wrap,
            };
            stackPanel.Children.Add(titleText);
            var hasTitle = PopupInfo != null && PopupInfo.Title != null && PopupInfo.Title.Trim().Length > 0;
            if (hasTitle)
            {
                titleText.SetBinding(InlineCollectionProperty, new Binding
                {
                    Path = new PropertyPath("Attributes"),
                    Source = this,
                    Converter = new StringFormatToInlineCollectionConverter(),
                    ConverterParameter = PopupInfo.Title
                });
            }
            if (PopupInfo != null && PopupInfo.Description != null && PopupInfo.Description.Trim().Length > 0)
            {
                if (!hasTitle)
                {
                    hasTitle = true;
                    titleText.SetBinding(InlineCollectionProperty, new Binding
                    {
                        Path = new PropertyPath("Attributes"),
                        Source = this,
                        Converter = new StringFormatToInlineCollectionConverter(),
                        ConverterParameter = PopupInfo.Description
                    });
                }
                var desc = new RichTextBlock
                {
                    FontSize = _controlContentThemeFontSize,
                    FontFamily = _contentControlThemeFontFamily
                };
                stackPanel.Children.Add(desc);

                var p = new Paragraph();
                desc.Blocks.Add(p);

                BindingOperations.SetBinding(p,HtmlToTextConverter.HtmlToInlinesProperty, new Binding
                {
                    Path = new PropertyPath("Attributes"),
                    Source = this,
                    Converter = new HtmlToTextConverter(),
                    ConverterParameter = PopupInfo.Description
                });
            }
            else //Show attribute list
            {
                List<FieldInfo> displayFields = null;
                if (PopupInfo != null && PopupInfo.FieldInfos != null)
                {
                    displayFields = new List<FieldInfo>(PopupInfo.FieldInfos.Where(a => a.IsVisible));
                }
                if (displayFields == null)
                    return;
                var attributes = Attributes as IDictionary<string, object>;
                foreach (var item in displayFields)
                {
                    var sp = new StackPanel();
                    stackPanel.Children.Add(sp);
                    var l = new TextBlock
                    {
                        Style = _baselineTextStyle,
                        Margin = new Thickness(0, 10, 0, 0),
                        Text = item.Label ?? item.FieldName,
                        Foreground = new SolidColorBrush(Colors.DarkGray),
                        TextWrapping = TextWrapping.Wrap,
                        TextTrimming = TextTrimming.WordEllipsis
                    };
                    sp.Children.Add(l);
                    if (!hasTitle)
                    {
                        hasTitle = true;
                        titleText.SetBinding(InlineCollectionProperty, new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                    var useHyperlink = attributes != null && attributes.ContainsKey(item.FieldName) &&
                        attributes[item.FieldName] is string && ((string)attributes[item.FieldName]).StartsWith("http");
                    if (useHyperlink || string.Equals("url", item.FieldName, StringComparison.OrdinalIgnoreCase))
                    {
                        var hyperlink = new HyperlinkButton();
                        sp.Children.Add(hyperlink);
                        hyperlink.SetBinding(HyperlinkButton.NavigateUriProperty,
                        new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.SetBinding(ContentProperty,
                        new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.Template = (ControlTemplate)XamlReader.Load(
                            "<ControlTemplate TargetType='HyperlinkButton' xmlns='http://schemas.microsoft.com/client/2007' >" +
                            "<TextBlock Text='{TemplateBinding Content}' Padding='0' Margin='0' RenderTransformOrigin='0.5,0.5' TextWrapping='Wrap' TextTrimming ='WordEllipsis'>" +
                            "<TextBlock.RenderTransform>" +
                            "<CompositeTransform TranslateY='5' />" +
                            "</TextBlock.RenderTransform>" +
                            "</TextBlock>" +
                            "</ControlTemplate>");
                        hyperlink.FontFamily = new FontFamily("Segoe UI Light");
                        hyperlink.FontWeight = FontWeights.Normal;
                        hyperlink.Margin = new Thickness(0);
                        hyperlink.Padding = new Thickness(0);
                    }
                    else
                    {
                        var t = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        sp.Children.Add(t);
                        t.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                }
            }
            if (PopupInfo != null && PopupInfo.MediaInfos != null)
            {
                foreach (var item in PopupInfo.MediaInfos)
                {
                    if (!string.IsNullOrEmpty(item.Title))
                    {
                        var mediaTitle = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            FontWeight = FontWeights.Bold,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaTitle);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path = new PropertyPath("Attributes"),
                                Source = this,
                                Converter = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Title
                            });
                        }
                        mediaTitle.SetBinding(TextBlock.TextProperty, new Binding
                        {
                             Path = new PropertyPath("Attributes"),
                             Source = this,
                             Converter = new StringFormatToStringConverter(),
                             ConverterParameter = item.Title
                        });
                    }
                    if (!string.IsNullOrEmpty(item.Caption))
                    {
                        var mediaCaption = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            FontStyle = FontStyle.Italic,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaCaption);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path = new PropertyPath("Attributes"),
                                Source = this,
                                Converter = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Caption
                            });
                        }
                        mediaCaption.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path = new PropertyPath("Attributes"),
                            Source = this,
                            Converter = new StringFormatToStringConverter(),
                            ConverterParameter = item.Caption
                        });
                    }

                    IEnumerable<KeyValuePair<string,string>> fieldMappings = null;
                    if (PopupInfo != null && PopupInfo.FieldInfos != null)
                    {
                        fieldMappings = from f in PopupInfo.FieldInfos
                                        select (new KeyValuePair<string, string>(f.FieldName, f.Label ?? f.FieldName));
                    }
                    BaseChart chart = null;
                    switch (item.Type)
                    {
                        case MediaType.Image:
                            var imageGrid = new Grid();
                            stackPanel.Children.Add(imageGrid);
                            if (!string.IsNullOrEmpty(item.Value.SourceUrl))
                            {
                                var image = new Image
                                {
                                    Margin = new Thickness(0,10,0,0),
                                    Width = 200d,
                                    Height = 200d,
                                    Stretch = Stretch.UniformToFill
                                };
                                imageGrid.Children.Add(image);
                                image.SetBinding(Image.SourceProperty, new Binding
                                {
                                    Path = new PropertyPath("Attributes"),
                                    Source = this,
                                    Converter = new StringFormatToBitmapSourceConverter(),
                                    ConverterParameter = item.Value.SourceUrl
                                });
                            }
                            if (!string.IsNullOrEmpty(item.Value.LinkUrl))
                            {
                                var hyperlinkButton = new HyperlinkButton
                                {
                                    Margin = new Thickness(0, 10, 0, 0),
                                    Width = 200d,
                                    Height = 200d
                                };
                                imageGrid.Children.Add(hyperlinkButton);
                                hyperlinkButton.SetBinding(HyperlinkButton.NavigateUriProperty, new Binding
                                {
                                    Path = new PropertyPath("Attributes"),
                                    Source = this,
                                    Converter = new StringFormatToUriConverter(),
                                    ConverterParameter = item.Value.LinkUrl
                                });
                            }
                            break;
                        case MediaType.BarChart:
                                chart = new BarChart();
                                break;
                        case MediaType.ColumnChart:
                                chart = new ColumnChart();
                                break;
                        case MediaType.LineChart:
                                chart = new LineChart();
                                break;
                        case MediaType.PieChart:
                                //string normalizeField = item.Value.NormalizeField;
                                chart = new PieChart();
                                break;
                    }
                    if (chart != null)
                    {
                        var fieldString = string.Join(",", item.Value.Fields);
                        var normalizeField = item.Value.NormalizeField;
                        if (!string.IsNullOrEmpty(normalizeField) && !normalizeField.Equals("null"))
                            fieldString += BaseChart.NormalizeSeparator + normalizeField;
                        chart.Margin = new Thickness(0, 10, 0, 0);
                        chart.Fields = fieldString;
                        chart.Height = 200;
                        chart.Width = 200;
                        chart.FontSize = 10d;
                        var keyValuePairs = fieldMappings as KeyValuePair<string, string>[] ?? fieldMappings.ToArray();
                        if (keyValuePairs.Any())
                        {
                            chart.KeyToLabelDictionary = new ResourceDictionary();
                            foreach (var pair in keyValuePairs)
                                chart.KeyToLabelDictionary[pair.Key] = pair.Value;
                        }
                        stackPanel.Children.Add(chart);
                        chart.SetBinding(DataContextProperty, new Binding
                        {
                            Path = new PropertyPath("Attributes"),
                            Source = this,
                        });
                    }
                }
            }
        }
        /// <summary>
        /// show paging links
        /// </summary>
        /// <param name="startPageIndex">0 based page index</param>
        /// <param name="totalPage"> total number of pages</param>
        /// <param name="totalLinkShown"></param>
        private void ShowPagingLink(int currentPageIndex)
        {
            if (this.totalPage <= 1)
            {
                return;
            }

            this.currentShownPageIndex = currentPageIndex;

            pagelink.Children.Clear();

            //show hyperlinks around the currentIndex

            if (currentPageIndex != 0)
            {
                HyperlinkButton hyperlink = new HyperlinkButton();
                hyperlink.Content = "<Prev";
                hyperlink.CommandParameter = (currentPageIndex).ToString();
                hyperlink.Click += new RoutedEventHandler(PageLinkClick);
                pagelink.Children.Add(hyperlink);

                hyperlink = new HyperlinkButton();
                hyperlink.Content = "1";
                hyperlink.Click += new RoutedEventHandler(PageLinkClick);
                pagelink.Children.Add(hyperlink);
            }
            else
            {
                HyperlinkButton hyperlink = new HyperlinkButton();
                hyperlink = new HyperlinkButton();
                hyperlink.Content = "1";
                hyperlink.Background = this.blackBrush;
                pagelink.Children.Add(hyperlink);
            }

            if (currentPageIndex > 4)
            {
                TextBlock textblock = new TextBlock();
                textblock.Text = "...";
                textblock.VerticalAlignment = VerticalAlignment.Center;
                pagelink.Children.Add(textblock);
            }

            for (int i = currentPageIndex - 3; i <= currentPageIndex; i++)
            {
                if (i <= 0)
                {
                    continue;
                }

                HyperlinkButton hyperlink = new HyperlinkButton();
                int content = i + 1;
                hyperlink.Content = content;

                if (i != currentPageIndex)
                {
                    hyperlink.Click += new RoutedEventHandler(PageLinkClick);
                }
                else
                {
                    hyperlink.Background = blackBrush;

                }

                pagelink.Children.Add(hyperlink);
            }

            int showPageTill = 0; //1 based pageIndex
            if (currentPageIndex < 5)
            {
                showPageTill = totalPage > 10 ? 10 : totalPage;
            }
            else
            {
                showPageTill = currentPageIndex + 4 > totalPage ? totalPage : currentPageIndex + 4;
            }

            for (int i = currentPageIndex + 1; i < showPageTill; i++)
            {
                HyperlinkButton hyperlink = new HyperlinkButton();
                int content = i + 1;
                hyperlink.Content = content;
                hyperlink.Click += new RoutedEventHandler(PageLinkClick);
                pagelink.Children.Add(hyperlink);
            }

            if (showPageTill < totalPage)
            {
                TextBlock textblock = new TextBlock();
                textblock.Text = "...";
                textblock.VerticalAlignment = VerticalAlignment.Center;
                pagelink.Children.Add(textblock);
            }

            if (currentPageIndex + 1 < showPageTill)
            {
                HyperlinkButton hyperlink = new HyperlinkButton();
                hyperlink.Content = "Next>";
                hyperlink.CommandParameter = (currentPageIndex + 2).ToString();
                hyperlink.Click += new RoutedEventHandler(PageLinkClick);
                pagelink.Children.Add(hyperlink);
            }
        }
        private static void CreateElement(InlineCollection parent, Node node, RichTextBlockStatus status)
        {
            switch (node)
            {
                case Element element:
                    switch (element.TagName.ToLower())
                    {
                        case "a":
                            {
                                // We want to change BaseUri easily, so we use `GetAttribute("href")` instead of `HtmlAnchorElement.Href`
                                var href = element.GetAttribute("href");

                                if (!status.TryCreateUri(href, out var uri))
                                    break;

                                parent.Add(new Run() { Text = " " });

                                var hyperlink = new Hyperlink()
                                {
                                    NavigateUri = uri,
                                    Foreground = status.Foreground
                                };

                                foreach (var child in element.ChildNodes)
                                {
                                    switch (child)
                                    {
                                        case HtmlImageElement childElement:
                                            if (CreateImage(element, status) is Image image)
                                            {
                                                if (hyperlink.Inlines.Count != 0)
                                                {
                                                    hyperlink.SetUri(href);
                                                    status.Hyperlinks.Add(hyperlink);
                                                    parent.Add(hyperlink);
                                                }

                                                var button = new HyperlinkButton()
                                                {
                                                    NavigateUri = uri,
                                                    Content = image,
                                                    RequestedTheme = status.RequestedTheme
                                                };
                                                button.SetUri(href);
                                                status.HyperlinkButtons.Add(button);
                                                parent.Add(new InlineUIContainer() { Child = button });

                                                hyperlink = new Hyperlink()
                                                {
                                                    NavigateUri = uri,
                                                    Foreground = status.Foreground
                                                };
                                            }
                                            break;
                                        default:
                                            CreateElement(hyperlink.Inlines, child, status);
                                            break;
                                    }
                                    break;
                                }

                                if (hyperlink.Inlines.Count != 0)
                                {
                                    hyperlink.SetUri(href);
                                    status.Hyperlinks.Add(hyperlink);
                                    parent.Add(hyperlink);
                                }

                                parent.Add(new Run() { Text = " " });
                            }
                            break;
                        case "img":
                            {
                                if (CreateImage(element, status) is Image image)
                                    parent.Add(new InlineUIContainer() { Child = image });
                            }
                            break;
                        case "strong":
                        case "b":
                            {
                                var span = new Span() { FontWeight = FontWeights.Bold };
                                CreateChildren(span.Inlines, element, status);
                                parent.Add(span);
                            }
                            break;
                        case "div":
                        case "font":
                        case "p":
                        case "span":
                            {
                                var span = new Span();
                                foreach (var s in ParseStyle(element.GetAttribute("style")))
                                    switch (s.Key)
                                    {
                                        case "font-size":
                                            {
                                                var value = s.Value;

                                                double fontSize;
                                                if (value.EndsWith("px"))
                                                    fontSize = double.Parse(value.Remove(value.Length - 2));
                                                else if (value.EndsWith("%"))
                                                    fontSize = 14 * double.Parse(value.Remove(value.Length - 1)) / 100;
                                                else
                                                    fontSize = 14 * double.Parse(value);

                                                span.FontSize = fontSize;
                                            }
                                            break;
                                        case "font-weight":
                                            switch (s.Value)
                                            {
                                                case "bold":
                                                    span.FontWeight = FontWeights.Bold;
                                                    break;
                                            }
                                            break;
                                    }

                                CreateChildren(span.Inlines, element, status);
                                parent.Add(span);
                            }
                            break;
                        case "br":
                            if (element.NextSibling is Text nextText &&
                                nextText.Data.StartsWith("\n"))
                                break;

                            parent.Add(new LineBreak());
                            break;
                        case "hr":
                            parent.Add(new LineBreak());

                            var line = new Border()
                            {
                                BorderThickness = new Thickness(0, 1, 0, 0),
                                BorderBrush = status.Foreground,
                                Margin = new Thickness(8, 0, 8, 0),
                                Height = 1,
                            };

                            if (status.ActualWidth > 16)
                                line.Width = status.ActualWidth - 16;

                            status.Lines.Add(line);
                            parent.Add(new InlineUIContainer() { Child = line });

                            parent.Add(new LineBreak());
                            break;
                        case "iframe": // Ignore
                        case "script":
                        case "noscript":
                            break;
#if DEBUG
                        default:
                            Debug.WriteLine($"Ignore unknown tag {element.TagName}");
                            break;
#endif

                    }
                    break;
                case Text text:
                    parent.Add(new Run() { Text = text.Data });
                    break;
            }
        }
        public async void GetBangumiInfo(string banID)
        {
            //string uri = "http://bangumi.bilibili.com/api/season?_device=wp&_ulv=10000&build=411005&platform=android&appkey=422fd9d7289a1dd9&ts="+APIHelper.GetTimeSpen+ "000&type=sp&sp_id=56719";
            //string sign=  APIHelper.GetSign(uri);
            //uri += "&sign=" + sign;
            try
            {
                pr_load.Visibility = Visibility.Visible;
                wc = new WebClientClass();
                string uri = "";
                    uri = string.Format("http://bangumi.bilibili.com/api/season?_device=wp&access_key={2}&_ulv=10000&build=411005&platform=android&appkey=422fd9d7289a1dd9&ts={0}000&type=bangumi&season_id={1}", ApiHelper.GetTimeSpen, banID, ApiHelper.access_key);
                uri += "&sign=" + ApiHelper.GetSign(uri);
                string result = await wc.GetResults(new Uri(uri));
                BangumiInfoModel model = new BangumiInfoModel();
                if ((int)JObject.Parse(result)["code"] == 0)
                {
                    model = JsonConvert.DeserializeObject<BangumiInfoModel>(JObject.Parse(result)["result"].ToString());
                    grid_Info.DataContext = model;
                    BangumiInfoModel m = JsonConvert.DeserializeObject<BangumiInfoModel>(model.user_season.ToString());
                    if (m.attention == 0)
                    {
                        font_icon.Glyph = "\uE006";
                        btn_concern.Label = "订阅";
                    }
                    else
                    {
                        font_icon.Glyph = "\uE00B";
                        btn_concern.Label = "取消订阅";
                    }

                    List<BangumiInfoModel> list = JsonConvert.DeserializeObject<List<BangumiInfoModel>>(model.episodes.ToString());
                    List<BangumiInfoModel> list2 = new List<BangumiInfoModel>();
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i].Num = i;
                        list2.Add(list[i]);
                        if (DownloadManage.Downloaded.Contains(list[i].danmaku.ToString()))
                        {
                            list[i].inLocal = true;
                        }
                    }
                    list_E.ItemsSource = list2;
                    List<BangumiInfoModel> list_CV = JsonConvert.DeserializeObject<List<BangumiInfoModel>>(model.actor.ToString());
                    txt_CV.Text = "";
                    foreach (BangumiInfoModel item in list_CV)
                    {
                        txt_CV.Text += string.Format("{0}:{1}\r\n", item.role, item.actor);
                    }
                    List<BangumiInfoModel> list_Tag = JsonConvert.DeserializeObject<List<BangumiInfoModel>>(model.tags.ToString());
                    Grid_tag.Children.Clear();
                    foreach (BangumiInfoModel item in list_Tag)
                    {
                        HyperlinkButton btn = new HyperlinkButton();
                        btn.DataContext = item;
                        btn.Margin = new Thickness(0, 0, 10, 0);
                        btn.Content = item.tag_name;
                        btn.Click += Btn_Click;
                        Grid_tag.Children.Add(btn);
                    }
                }
                if ((int)JObject.Parse(result)["code"] == -3)
                {
                    messShow.Show("密钥注册失败,请联系作者",3000);
                }
                if ((int)JObject.Parse(result)["code"] == 10)
                {
                    messShow.Show(JObject.Parse(result)["message"].ToString(), 3000);
                }
            }
            catch (Exception ex)
            {
                messShow.Show("发生错误\r\n" + ex.Message, 3000);
            }
            finally
            {
                pr_load.Visibility = Visibility.Collapsed;

            }
        }
        private void createSettingsFlyout(SettingsFlyout sf, Gig g)
        {
            sf.HeaderText = g.title;
            sf.FlyoutWidth = SettingsFlyout.SettingsFlyoutWidth.Wide;
            StackPanel sp = new StackPanel() { Orientation = Orientation.Vertical };
            #region Venue
            sp.Children.Add(new TextBlock() { Text = "Venue", Style = this.Resources["HeaderStyle"] as Style });
            if (g.venue.url != null)
            {
                HyperlinkButton hb = new HyperlinkButton();
                hb.Content = g.venue.Title;
                hb.Tag = g.venue.id;
                hb.Style = this.Resources["HyperStyle"] as Style;
                hb.Click+=hb_Click_Venue;
                sp.Children.Add(hb);
            }
            else
            {
                sp.Children.Add(new TextBlock { Text = g.venue.Title, Style = this.Resources["ContentStyle"] as Style });
            }
            sp.Children.Add(new TextBlock() { Text = "Artists", Style = this.Resources["HeaderStyle"] as Style });
            #endregion
            #region Artists
            StackPanel artistPanel = new StackPanel();
            foreach (string s in g.artists.artist)
            {
                HyperlinkButton hb = new HyperlinkButton() { Content = s, Style = this.Resources["HyperStyle"] as Style };
                hb.Click += hb_Click;
                artistPanel.Children.Add(hb);
            }
            sp.Children.Add(artistPanel);
            #endregion
            #region Street
            if (g.venue.location.street != "")
            {
                sp.Children.Add(new TextBlock() { Text = "Address", Style = this.Resources["HeaderStyle"] as Style });
                sp.Children.Add(new TextBlock() { Text = g.venue.location.street, Style = this.Resources["ContentStyle"] as Style });
            }
            #endregion
            #region City
            sp.Children.Add(new TextBlock() { Text = "City", Style = this.Resources["HeaderStyle"] as Style });
            sp.Children.Add(new TextBlock() { Text = g.venue.location.city, Style = this.Resources["ContentStyle"] as Style });
            #endregion
            #region Time
            sp.Children.Add(new TextBlock() { Text = "Time", Style = this.Resources["HeaderStyle"] as Style });
            sp.Children.Add(new TextBlock() { Text = g.startDate.Substring(0, g.startDate.Length-3), Style = this.Resources["ContentStyle"] as Style });
            #endregion
            sp.Children.Add(new TextBlock() { Text = "More Details", Style = this.Resources["HeaderStyle"] as Style });
            sp.Children.Add(new HyperlinkButton() { Content = g.url, NavigateUri =new Uri( g.url), Style = this.Resources["HyperStyle"] as Style });
            
            Map m = new Map();
            m.Height = 400;
            Pushpin p = new Pushpin();
            MapLayer.SetPosition(p, new Location(double.Parse(g.venue.location.point.lat), double.Parse(g.venue.location.point.longt)));
            m.Children.Add(p);
            m.ZoomLevel = 15;
            m.Credentials = MAPS_KEY;
            m.ShowScaleBar = false;
            m.ShowNavigationBar = false;
            m.SetView(new Location(double.Parse(g.venue.location.point.lat), double.Parse(g.venue.location.point.longt)));
            sp.Children.Add(m);
           
           







            sf.ContentBackgroundBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
            sf.Content = sp;
        }
        private void RegisteredRepairs_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Repair selectedRepair = repairs[RegisteredRepairs.SelectedIndex];
            SelectedRepairDetails.Children.Clear();

            var selectedRepairProperties = selectedRepair.GetType().GetRuntimeProperties();

            foreach (var property in selectedRepairProperties)
            {
                var propertyStack = new StackPanel();
                propertyStack.Orientation = Orientation.Horizontal;
                SelectedRepairDetails.Children.Add(propertyStack);

                var propertyNameGrid = new Grid();
                propertyNameGrid.Width = 200;
                propertyStack.Children.Add(propertyNameGrid);

                var propertyValueGrid = new Grid();
                propertyStack.Children.Add(propertyValueGrid);
                if (property.Name == "ExchangedParts")
                {
                    var propertyNameBlock = new TextBlock();
                    propertyNameBlock.Text = "ExchangedParts";
                    propertyNameGrid.Children.Add(propertyNameBlock);

                    HyperlinkButton hb = new HyperlinkButton();
                    dynamic list = property.GetValue(selectedRepair);
                    List<Part> parts = list as List<Part>;
                    hb.Content = parts.Count().ToString();
                    hb.Click += HyperlinkButton_Click;

                    propertyValueGrid.Children.Add(hb);
                }
                else if (property.GetValue(selectedRepair) != null)
                {
                    var propertyNameBlock = new TextBlock();
                    string propertyName;

                    var descriptionAttribute = property.GetCustomAttributes().FirstOrDefault(attr => attr.GetType().Name == "DescriptionAttribute");

                    if (descriptionAttribute != null)
                    {
                        propertyName = descriptionAttribute.GetType().GetRuntimeProperty("Name").GetValue(descriptionAttribute).ToString().ToUpper();
                    }
                    else
                    {
                        propertyName = property.Name.ToString().ToUpper();
                    }

                    propertyNameBlock.Text = propertyName;
                    propertyNameGrid.Children.Add(propertyNameBlock);

                    var propertyValue = new TextBlock();
                    var value = property.GetValue(selectedRepair).ToString();
                    propertyValue.Text = value;
                    propertyValueGrid.Children.Add(propertyValue);
                }
            }
        }
        private static Inline GenerateHyperLink(HtmlNode node)
        {
            Span s = new Span();
            InlineUIContainer iui = new InlineUIContainer();
          
            Debug.WriteLine(node.Attributes["href"].Value);
            HyperlinkButton hb;
            string lk = node.Attributes["href"].Value;
            if (!lk.Contains("http"))
            {
                lk = string.Format("http://ifixit.com/{0}", lk);
            }
            hb = new HyperlinkButton() { NavigateUri = new Uri(lk, UriKind.RelativeOrAbsolute), Content = CleanText(node.InnerText),  };

            if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI"))
                hb.Style = (Style)Application.Current.Resources["RTLinkLI"];
            else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText)))
                hb.Style = (Style)Application.Current.Resources["RTLinkOnly"];
            else
                hb.Style = (Style)Application.Current.Resources["RTLink"];

            iui.Child = hb;
         
            s.Inlines.Add(iui);

            return s;
        }