コード例 #1
0
        private FrameworkElement ProcessAuthorDate(TLPageBase page, TLPageBlockAuthorDate block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var textBlock = new TextBlock {
                Style = Resources["AuthorDateBlockStyle"] as Style
            };

            textBlock.FontSize = 15;

            if (block.Author.TypeId != TLType.TextEmpty)
            {
                var span = new Span();
                textBlock.Inlines.Add(new Run {
                    Text = "By "
                });
                textBlock.Inlines.Add(span);
                ProcessRichText(block.Author, span);

                textBlock.Inlines.Add(new Run {
                    Text = " — "
                });
            }

            //textBlock.Inlines.Add(new Run { Text = DateTimeFormatter.LongDate.Format(BindConvert.Current.DateTime(block.PublishedDate)) });
            textBlock.Inlines.Add(new Run {
                Text = BindConvert.Current.DateTime(block.PublishedDate).ToString("dd MMMM yyyy")
            });
            return(textBlock);
        }
コード例 #2
0
        private FrameworkElement ProcessList(TLPageBase page, TLPageBlockList block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var textBlock = new RichTextBlock();

            textBlock.FontSize     = 17;
            textBlock.TextWrapping = TextWrapping.Wrap;

            for (int i = 0; i < block.Items.Count; i++)
            {
                var text = block.Items[i];
                var par  = new Paragraph();
                par.TextIndent = -24;
                par.Margin     = new Thickness(24, 0, 0, 0);

                var span = new Span();
                par.Inlines.Add(new Run {
                    Text = block.Ordered ? (i + 1) + ".\t" : "•\t"
                });
                par.Inlines.Add(span);
                ProcessRichText(text, span);
                textBlock.Blocks.Add(par);
            }

            return(textBlock);
        }
コード例 #3
0
        private FrameworkElement ProcessChannel(TLPageBase page, TLPageBlockChannel channel, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var chat = channel.Channel as TLChannel;

            if (chat.IsMin)
            {
                chat = InMemoryCacheService.Current.GetChat(chat.Id) as TLChannel ?? channel.Channel as TLChannel;
            }

            var button = new Button
            {
                Style   = Resources["ChannelBlockStyle"] as Style,
                Content = chat
            };

            if (chat.IsMin && chat.HasUsername)
            {
                MTProtoService.Current.ResolveUsernameAsync(chat.Username,
                                                            result =>
                {
                    Execute.BeginOnUIThread(() => button.Content = result.Chats.FirstOrDefault());
                });
            }

            return(button);
        }
コード例 #4
0
        private FrameworkElement ProcessVideo(TLPageBase page, TLPageBlockVideo block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var video = documents.FirstOrDefault(x => x.Id == block.VideoId);

            if (video != null)
            {
                var galleryItem = new GalleryDocumentItem(video as TLDocument, block.Caption?.ToString());
                ViewModel.Gallery.Items.Add(galleryItem);

                var element = new StackPanel {
                    Style = Resources["BlockVideoStyle"] as Style
                };

                var child = new ImageView();
                child.Source              = (ImageSource)DefaultPhotoConverter.Convert(video, true);
                child.Constraint          = video;
                child.DataContext         = galleryItem;
                child.Click              += Image_Click;
                child.HorizontalAlignment = HorizontalAlignment.Center;

                var transferBinding = new Binding();
                transferBinding.Path   = new PropertyPath("IsTransferring");
                transferBinding.Source = video;

                var transfer = new TransferButton();
                transfer.Completed   += (s, args) => Image_Click(child, null);
                transfer.Transferable = video;
                transfer.Style        = Application.Current.Resources["MediaTransferButtonStyle"] as Style;
                transfer.SetBinding(TransferButton.IsTransferringProperty, transferBinding);

                var progressBinding = new Binding();
                progressBinding.Path   = new PropertyPath("Progress");
                progressBinding.Source = video;

                var progress = new ProgressBarRing();
                progress.Background       = new SolidColorBrush(Colors.Transparent);
                progress.Foreground       = new SolidColorBrush(Colors.White);
                progress.IsHitTestVisible = false;
                progress.SetBinding(ProgressBarRing.ValueProperty, progressBinding);

                var grid = new Grid();
                grid.Children.Add(child);
                grid.Children.Add(transfer);
                grid.Children.Add(progress);

                element.Children.Add(grid);

                var caption = ProcessText(page, block, photos, documents, true);
                if (caption != null)
                {
                    caption.Margin = new Thickness(0, 8, 0, 0);
                    element.Children.Add(caption);
                }

                return(element);
            }

            return(null);
        }
コード例 #5
0
        private FrameworkElement ProcessDivider(TLPageBase page, TLPageBlockDivider block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new Rectangle {
                Style = Resources["BlockDividerStyle"] as Style
            };

            return(element);
        }
コード例 #6
0
        private FrameworkElement ProcessAnchor(TLPageBase page, TLPageBlockAnchor block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new Border();

            _anchors[block.Name] = element;

            return(element);
        }
コード例 #7
0
ファイル: TLWebPage.cs プロジェクト: yuukidesu9/telegram-wp
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);
            Flags      = GetObject <TLInt>(bytes, ref position);
            Id         = GetObject <TLLong>(bytes, ref position);
            Url        = GetObject <TLString>(bytes, ref position);
            DisplayUrl = GetObject <TLString>(bytes, ref position);
            Hash       = GetObject <TLInt>(bytes, ref position);
            if (IsSet(Flags, (int)WebPageFlags.Type))
            {
                Type = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.SiteName))
            {
                SiteName = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Title))
            {
                Title = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Description))
            {
                Description = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Photo))
            {
                Photo = GetObject <TLPhotoBase>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Embed))
            {
                EmbedUrl  = GetObject <TLString>(bytes, ref position);
                EmbedType = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.EmbedSize))
            {
                EmbedWidth  = GetObject <TLInt>(bytes, ref position);
                EmbedHeight = GetObject <TLInt>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Duration))
            {
                Duration = GetObject <TLInt>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Author))
            {
                Author = GetObject <TLString>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.Document))
            {
                Document = GetObject <TLDocumentBase>(bytes, ref position);
            }
            if (IsSet(Flags, (int)WebPageFlags.CachedPage))
            {
                CachedPage = GetObject <TLPageBase>(bytes, ref position);
            }

            return(this);
        }
コード例 #8
0
ファイル: TLWebPage.cs プロジェクト: yuukidesu9/telegram-wp
        public override TLObject FromStream(Stream input)
        {
            Flags      = GetObject <TLInt>(input);
            Id         = GetObject <TLLong>(input);
            Url        = GetObject <TLString>(input);
            DisplayUrl = GetObject <TLString>(input);
            Hash       = GetObject <TLInt>(input);
            if (IsSet(Flags, (int)WebPageFlags.Type))
            {
                Type = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.SiteName))
            {
                SiteName = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Title))
            {
                Title = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Description))
            {
                Description = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Photo))
            {
                Photo = GetObject <TLPhotoBase>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Embed))
            {
                EmbedUrl  = GetObject <TLString>(input);
                EmbedType = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.EmbedSize))
            {
                EmbedWidth  = GetObject <TLInt>(input);
                EmbedHeight = GetObject <TLInt>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Duration))
            {
                Duration = GetObject <TLInt>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Author))
            {
                Author = GetObject <TLString>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.Document))
            {
                Document = GetObject <TLDocumentBase>(input);
            }
            if (IsSet(Flags, (int)WebPageFlags.CachedPage))
            {
                CachedPage = GetObject <TLPageBase>(input);
            }

            return(this);
        }
コード例 #9
0
        private FrameworkElement ProcessPhoto(TLPageBase page, TLPageBlockPhoto block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var photo = photos.FirstOrDefault(x => x.Id == block.PhotoId);

            if (photo != null)
            {
                var galleryItem = new GalleryPhotoItem(photo as TLPhoto, block.Caption?.ToString());
                ViewModel.Gallery.Items.Add(galleryItem);

                var element = new StackPanel {
                    Style = Resources["BlockPhotoStyle"] as Style
                };

                var child = new ImageView();
                child.Source              = (ImageSource)DefaultPhotoConverter.Convert(photo, true);
                child.Constraint          = photo;
                child.DataContext         = galleryItem;
                child.Click              += Image_Click;
                child.HorizontalAlignment = HorizontalAlignment.Center;

                var transferBinding = new Binding();
                transferBinding.Path   = new PropertyPath("IsTransferring");
                transferBinding.Source = photo;

                var progressBinding = new Binding();
                progressBinding.Path   = new PropertyPath("Progress");
                progressBinding.Source = photo;

                var transfer = new TransferButton();
                transfer.Completed   += (s, args) => Image_Click(child, null);
                transfer.Transferable = photo;
                transfer.Style        = Application.Current.Resources["MediaTransferButtonStyle"] as Style;
                transfer.SetBinding(TransferButton.IsTransferringProperty, transferBinding);
                transfer.SetBinding(TransferButton.ProgressProperty, progressBinding);

                var grid = new Grid();
                grid.Children.Add(child);
                grid.Children.Add(transfer);

                element.Children.Add(grid);

                var caption = ProcessText(page, block, photos, documents, true);
                if (caption != null)
                {
                    caption.Margin = new Thickness(0, 8, 0, 0);
                    element.Children.Add(caption);
                }

                return(element);
            }

            return(null);
        }
コード例 #10
0
        private FrameworkElement ProcessSlideshow(TLPageBase page, TLPageBlockSlideshow block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockSlideshowStyle"] as Style
            };

            var items = new List <ImageView>();

            foreach (var item in block.Items)
            {
                if (item is TLPageBlockPhoto photoBlock)
                {
                    var photo = photos.FirstOrDefault(x => x.Id == photoBlock.PhotoId);
                    if (photo != null)
                    {
                        var image = new ImageView();
                        image.Source     = (ImageSource)DefaultPhotoConverter.Convert(photo, true);
                        image.Constraint = photo;

                        items.Add(image);
                    }
                }
                else if (item is TLPageBlockVideo videoBlock)
                {
                    var video = documents.FirstOrDefault(x => x.Id == videoBlock.VideoId);
                    if (video != null)
                    {
                        var child = new ImageView();
                        child.Source     = (ImageSource)DefaultPhotoConverter.Convert(video, true);
                        child.Constraint = video;

                        items.Add(child);
                    }
                }
            }

            var flip = new FlipView();

            flip.ItemsSource = items;

            element.Children.Add(flip);

            var caption = ProcessText(page, block, photos, documents, true);

            if (caption != null)
            {
                caption.Margin = new Thickness(0, _padding, 0, 0);
                element.Children.Add(caption);
            }

            return(element);
        }
コード例 #11
0
        private FrameworkElement ProcessPreformatted(TLPageBase page, TLPageBlockPreformatted block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockPreformattedStyle"] as Style
            };

            var text = ProcessText(page, block, photos, documents, false);

            if (text != null)
            {
                element.Children.Add(text);
            }

            return(element);
        }
コード例 #12
0
        private FrameworkElement ProcessPullquote(TLPageBase page, TLPageBlockPullquote block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockPullquoteStyle"] as Style
            };

            var text = ProcessText(page, block, photos, documents, false);

            if (text != null)
            {
                element.Children.Add(text);
            }

            var caption = ProcessText(page, block, photos, documents, true);

            if (caption != null)
            {
                element.Children.Add(caption);
            }

            return(element);
        }
コード例 #13
0
        private FrameworkElement ProcessEmbedPost(TLPageBase page, TLPageBlockEmbedPost block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockEmbedPostStyle"] as Style
            };

            var header = new Grid();

            header.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            header.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            header.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            header.ColumnDefinitions.Add(new ColumnDefinition());
            header.Margin = new Thickness(_padding, 0, 0, _padding);

            var photo   = photos.FirstOrDefault(x => x.Id == block.AuthorPhotoId);
            var ellipse = new Ellipse();

            ellipse.Width  = 36;
            ellipse.Height = 36;
            ellipse.Margin = new Thickness(0, 0, _padding, 0);
            ellipse.Fill   = new ImageBrush {
                ImageSource = (ImageSource)DefaultPhotoConverter.Convert(photo, true), Stretch = Stretch.UniformToFill, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center
            };
            Grid.SetRowSpan(ellipse, 2);

            var textAuthor = new TextBlock();

            textAuthor.Text = block.Author;
            textAuthor.VerticalAlignment = VerticalAlignment.Bottom;
            Grid.SetColumn(textAuthor, 1);
            Grid.SetRow(textAuthor, 0);

            var textDate = new TextBlock();

            textDate.Text = BindConvert.Current.DateTime(block.Date).ToString("dd MMMM yyyy");
            textDate.VerticalAlignment = VerticalAlignment.Top;
            textDate.Style             = (Style)Resources["CaptionTextBlockStyle"];
            textDate.Foreground        = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
            Grid.SetColumn(textDate, 1);
            Grid.SetRow(textDate, 1);

            header.Children.Add(ellipse);
            header.Children.Add(textAuthor);
            header.Children.Add(textDate);

            element.Children.Add(header);

            TLPageBlockBase  previousBlock   = null;
            FrameworkElement previousElement = null;

            foreach (var subBlock in block.Blocks)
            {
                var subLayout = ProcessBlock(page, subBlock, photos, documents);
                var spacing   = SpacingBetweenBlocks(previousBlock, block);

                if (subLayout != null)
                {
                    subLayout.Margin = new Thickness(_padding, spacing, _padding, 0);
                    element.Children.Add(subLayout);
                }

                previousBlock   = block;
                previousElement = subLayout;
            }

            return(element);
        }
コード例 #14
0
        private FrameworkElement ProcessCollage(TLPageBase page, TLPageBlockCollage block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockCollageStyle"] as Style
            };

            var items = new List <Image>();

            foreach (var item in block.Items)
            {
                if (item is TLPageBlockPhoto photoBlock)
                {
                    var photo = photos.FirstOrDefault(x => x.Id == photoBlock.PhotoId);
                    if (photo != null)
                    {
                        var child = new Image();
                        child.Source  = (ImageSource)DefaultPhotoConverter.Convert(photo, true);
                        child.Width   = 72;
                        child.Height  = 72;
                        child.Stretch = Stretch.UniformToFill;
                        child.Margin  = new Thickness(0, 0, 4, 4);

                        items.Add(child);
                    }
                }
                else if (item is TLPageBlockVideo videoBlock)
                {
                    var video = documents.FirstOrDefault(x => x.Id == videoBlock.VideoId);
                    if (video != null)
                    {
                        var child = new Image();
                        child.Source  = (ImageSource)DefaultPhotoConverter.Convert(video, true);
                        child.Width   = 72;
                        child.Height  = 72;
                        child.Stretch = Stretch.UniformToFill;
                        child.Margin  = new Thickness(0, 0, 4, 4);

                        items.Add(child);
                    }
                }
            }

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });

            for (int i = 0; i < items.Count; i++)
            {
                var y = i / 3;
                var x = i % 3;

                grid.Children.Add(items[i]);
                Grid.SetRow(items[i], y);
                Grid.SetColumn(items[i], x);

                if (x == 0)
                {
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    });
                }
            }

            element.Children.Add(grid);

            var caption = ProcessText(page, block, photos, documents, true);

            if (caption != null)
            {
                caption.Margin = new Thickness(0, _padding, 0, 0);
                element.Children.Add(caption);
            }

            return(element);
        }
コード例 #15
0
        private FrameworkElement ProcessEmbed(TLPageBase page, TLPageBlockEmbed block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockEmbedStyle"] as Style
            };

            FrameworkElement child = null;

            //if (block.HasPosterPhotoId)
            //{
            //    var photo = page.Photos.FirstOrDefault(x => x.Id == block.PosterPhotoId);
            //    var image = new ImageView();
            //    image.Source = (ImageSource)DefaultPhotoConverter.Convert(photo, "thumbnail");
            //    image.Constraint = photo;
            //    child = image;
            //}
            if (block.HasHtml)
            {
                var view = new WebView();
                if (!block.IsAllowScrolling)
                {
                    view.NavigationCompleted += OnWebViewNavigationCompleted;
                }
                view.NavigateToString(block.Html.Replace("src=\"//", "src=\"https://"));

                var ratio = new RatioControl();
                ratio.MaxWidth  = block.W;
                ratio.MaxHeight = block.H;
                ratio.Content   = view;
                ratio.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                ratio.VerticalContentAlignment   = VerticalAlignment.Stretch;
                child = ratio;
            }
            else if (block.HasUrl)
            {
                var view = new WebView();
                if (!block.IsAllowScrolling)
                {
                    view.NavigationCompleted += OnWebViewNavigationCompleted;
                }
                view.Navigate(new Uri(block.Url));

                var ratio = new RatioControl();
                ratio.MaxWidth  = block.W;
                ratio.MaxHeight = block.H;
                ratio.Content   = view;
                ratio.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                ratio.VerticalContentAlignment   = VerticalAlignment.Stretch;
                child = ratio;
            }

            element.Children.Add(child);

            var caption = ProcessText(page, block, photos, documents, true);

            if (caption != null)
            {
                caption.Margin = new Thickness(0, _padding, 0, 0);
                element.Children.Add(caption);
            }

            return(element);
        }
コード例 #16
0
        private FrameworkElement ProcessBlock(TLPageBase page, TLPageBlockBase block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            switch (block)
            {
            case TLPageBlockCover cover:
                return(ProcessCover(page, cover, photos, documents));

            case TLPageBlockAuthorDate authorDate:
                return(ProcessAuthorDate(page, authorDate, photos, documents));

            case TLPageBlockHeader header:
            case TLPageBlockSubheader subheader:
            case TLPageBlockTitle title:
            case TLPageBlockSubtitle subtitle:
            case TLPageBlockFooter footer:
            case TLPageBlockParagraph paragraph:
                return(ProcessText(page, block, photos, documents, false));

            case TLPageBlockBlockquote blockquote:
                return(ProcessBlockquote(page, blockquote, photos, documents));

            case TLPageBlockDivider divider:
                return(ProcessDivider(page, divider, photos, documents));

            case TLPageBlockPhoto photo:
                return(ProcessPhoto(page, photo, photos, documents));

            case TLPageBlockList list:
                return(ProcessList(page, list, photos, documents));

            case TLPageBlockVideo video:
                return(ProcessVideo(page, video, photos, documents));

            case TLPageBlockEmbedPost embedPost:
                return(ProcessEmbedPost(page, embedPost, photos, documents));

            case TLPageBlockSlideshow slideshow:
                return(ProcessSlideshow(page, slideshow, photos, documents));

            case TLPageBlockCollage collage:
                return(ProcessCollage(page, collage, photos, documents));

            case TLPageBlockEmbed embed:
                return(ProcessEmbed(page, embed, photos, documents));

            case TLPageBlockPullquote pullquote:
                return(ProcessPullquote(page, pullquote, photos, documents));

            case TLPageBlockAnchor anchor:
                return(ProcessAnchor(page, anchor, photos, documents));

            case TLPageBlockPreformatted preformatted:
                return(ProcessPreformatted(page, preformatted, photos, documents));

            case TLPageBlockChannel channel:
                return(ProcessChannel(page, channel, photos, documents));

            case TLPageBlockUnsupported unsupported:
                Debug.WriteLine("Unsupported block type: " + block.GetType());
                break;
            }

            return(null);
        }
コード例 #17
0
        private FrameworkElement ProcessText(TLPageBase page, TLPageBlockBase block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents, bool caption)
        {
            TLRichTextBase text = null;

            switch (block)
            {
            case TLPageBlockTitle title:
                text = title.Text;
                break;

            case TLPageBlockSubtitle subtitle:
                text = subtitle.Text;
                break;

            case TLPageBlockHeader header:
                text = header.Text;
                break;

            case TLPageBlockSubheader subheader:
                text = subheader.Text;
                break;

            case TLPageBlockFooter footer:
                text = footer.Text;
                break;

            case TLPageBlockParagraph paragraph:
                text = paragraph.Text;
                break;

            case TLPageBlockPreformatted preformatted:
                text = preformatted.Text;
                break;

            case TLPageBlockPhoto photo:
                text = photo.Caption;
                break;

            case TLPageBlockVideo video:
                text = video.Caption;
                break;

            case TLPageBlockSlideshow slideshow:
                text = slideshow.Caption;
                break;

            case TLPageBlockEmbed embed:
                text = embed.Caption;
                break;

            case TLPageBlockEmbedPost embedPost:
                text = embedPost.Caption;
                break;

            case TLPageBlockBlockquote blockquote:
                text = caption ? blockquote.Caption : blockquote.Text;
                break;

            case TLPageBlockPullquote pullquote:
                text = caption ? pullquote.Caption : pullquote.Text;
                break;
            }

            if (text != null && text.TypeId != TLType.TextEmpty)
            {
                var textBlock = new RichTextBlock();
                var span      = new Span();
                var paragraph = new Paragraph();
                paragraph.Inlines.Add(span);
                textBlock.Blocks.Add(paragraph);
                textBlock.TextWrapping = TextWrapping.Wrap;

                //textBlock.Margin = new Thickness(12, 0, 12, 12);
                ProcessRichText(text, span);

                switch (block.TypeId)
                {
                case TLType.PageBlockTitle:
                    textBlock.FontSize   = 28;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockSubtitle:
                    textBlock.FontSize = 17;
                    //textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockHeader:
                    textBlock.FontSize   = 24;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockSubheader:
                    textBlock.FontSize   = 19;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockParagraph:
                    textBlock.FontSize = 17;
                    break;

                case TLType.PageBlockPreformatted:
                    textBlock.FontSize = 16;
                    break;

                case TLType.PageBlockFooter:
                    textBlock.FontSize   = 15;
                    textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    //textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockPhoto:
                case TLType.PageBlockVideo:
                    textBlock.FontSize      = 15;
                    textBlock.Foreground    = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockSlideshow:
                case TLType.PageBlockEmbed:
                case TLType.PageBlockEmbedPost:
                    textBlock.FontSize   = 15;
                    textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    //textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockBlockquote:
                    textBlock.FontSize = caption ? 15 : 17;
                    if (caption)
                    {
                        textBlock.Foreground    = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                        textBlock.TextAlignment = TextAlignment.Center;
                    }
                    break;

                case TLType.PageBlockPullquote:
                    var pullquoteBlock = block as TLPageBlockPullquote;
                    textBlock.FontSize = caption ? 15 : 17;
                    if (caption)
                    {
                        textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    }
                    else
                    {
                        textBlock.FontFamily = new FontFamily("Times New Roman");
                        //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                        textBlock.TextAlignment = TextAlignment.Center;
                    }
                    break;
                }

                return(textBlock);
            }

            return(null);
        }
コード例 #18
0
 private FrameworkElement ProcessCover(TLPageBase page, TLPageBlockCover block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
 {
     return(ProcessBlock(page, block.Cover, photos, documents));
 }