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); }
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 <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 galleryItem = new GalleryPhotoItem(photo as TLPhoto, photoBlock.Caption?.ToString()); ViewModel.Gallery.Items.Add(galleryItem); var child = new ImageView(); child.Source = (ImageSource)DefaultPhotoConverter.Convert(photo, true); child.DataContext = galleryItem; child.Click += Image_Click; 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 galleryItem = new GalleryDocumentItem(video as TLDocument, videoBlock.Caption?.ToString()); ViewModel.Gallery.Items.Add(galleryItem); var child = new ImageView(); child.Source = (ImageSource)DefaultPhotoConverter.Convert(video, true); child.DataContext = galleryItem; child.Click += Image_Click; 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) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); for (int i = 0; i < items.Count; i++) { var y = i / 4; var x = i % 4; 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); }