Esempio n. 1
0
        private bool SetGifTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "GIF";
            MessageLabel.Text = string.Empty;

            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                if (!string.IsNullOrWhiteSpace(documentMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += documentMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                }

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(documentMedia.Document, true);
            }

            return(true);
        }
Esempio n. 2
0
        private bool SetGameTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "🎮 Game";
            MessageLabel.Text = string.Empty;

            var gameMedia = message.Media as TLMessageMediaGame;

            if (gameMedia != null && gameMedia.Game != null)
            {
                ServiceLabel.Text = $"🎮 {gameMedia.Game.Title}";

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(gameMedia.Game.Photo, true);
            }

            return(true);
        }
Esempio n. 3
0
        private bool SetWebPageTemplate(TLMessage message, string title)
        {
            var webPageMedia = message.Media as TLMessageMediaWebPage;

            if (webPageMedia != null)
            {
                var webPage = webPageMedia.WebPage as TLWebPage;
                if (webPage != null && webPage.Photo != null && webPage.Type != null)
                {
                    Visibility = Visibility.Visible;

                    FindName(nameof(ThumbRoot));
                    if (ThumbRoot != null)
                    {
                        ThumbRoot.Visibility = Visibility.Visible;
                    }

                    TitleLabel.Text   = GetFromLabel(message, title);
                    ServiceLabel.Text = string.Empty;
                    MessageLabel.Text = message.Message.Replace("\r\n", "\n").Replace('\n', ' ');

                    ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                    ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(webPage.Photo, true);
                }
                else
                {
                    return(SetTextTemplate(message, title));
                }
            }

            return(true);
        }
Esempio n. 4
0
        public void UpdateMessage(MessageViewModel message)
        {
            _message = message;

            var game = message.Content as MessageGame;

            if (game == null)
            {
                return;
            }

            TitleLabel.Text    = game.Game.Title;
            Texture.Constraint = game.Game.Animation ?? (object)game.Game.Photo;
            Texture.Source     = DefaultPhotoConverter.Convert(game.Game.Animation ?? (object)game.Game.Photo, false) as ImageSource;

            if (game.Game.Text == null || string.IsNullOrEmpty(game.Game.Text.Text))
            {
                Span.Inlines.Clear();
                Span.Inlines.Add(new Run {
                    Text = game.Game.Description
                });
            }
            else
            {
                Span.Inlines.Clear();
                ReplaceEntities(Span, game.Game.Text);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void SetCall(TLTuple <TLPhoneCallState, TLPhoneCallBase, TLUserBase, string> tuple)
        {
            if (_disposed)
            {
                return;
            }

            if (_state != tuple.Item1)
            {
                Debug.WriteLine("[{0:HH:mm:ss.fff}] State changed in app: " + tuple.Item1, DateTime.Now);

                _state             = tuple.Item1;
                StateLabel.Content = StateToLabel(tuple.Item1);

                if (tuple.Item1 == TLPhoneCallState.Established)
                {
                    SignalBarsLabel.Visibility = Visibility.Visible;
                    StartUpdatingCallDuration();

                    if (_emojis != null)
                    {
                        for (int i = 0; i < _emojis.Length; i++)
                        {
                            var imageLarge = FindName($"LargeEmoji{i}") as Image;
                            var source     = Emoji.BuildUri(_emojis[i]);

                            imageLarge.Source = new BitmapImage(new Uri(source));
                        }
                    }
                }
            }

            if (tuple.Item2 is TLPhoneCallRequested call)
            {
            }

            if (tuple.Item3 is TLUser user)
            {
                if (user.HasPhoto && user.Photo is TLUserProfilePhoto)
                {
                    Image.Source         = DefaultPhotoConverter.Convert(user.Photo, true) as ImageSource;
                    GrabPanel.Background = new SolidColorBrush(Colors.Transparent);
                }
                else
                {
                    Image.Source         = null;
                    GrabPanel.Background = BindConvert.Current.Bubble(user.Id);
                }

                FromLabel.Text        = user.FullName;
                DescriptionLabel.Text = string.Format(Strings.Android.CallEmojiKeyTooltip, user.FirstName);
            }

            if (tuple.Item4.Length > 0)
            {
                _emojis = tuple.Item4.Split(' ');
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private bool SetDocumentTemplate(TLMessage message, string title)
        {
            var documentMedia = message.Media as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                var document = documentMedia.Document as TLDocument;
                if (document != null)
                {
                    var photoSize       = document.Thumb as TLPhotoSize;
                    var photoCachedSize = document.Thumb as TLPhotoCachedSize;
                    if (photoCachedSize != null || photoSize != null)
                    {
                        Visibility = Visibility.Visible;

                        FindName(nameof(ThumbRoot));
                        if (ThumbRoot != null)
                        {
                            ThumbRoot.Visibility = Visibility.Visible;
                        }

                        ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                        ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(documentMedia.Document, true);
                    }
                    else
                    {
                        Visibility = Visibility.Visible;

                        if (ThumbRoot != null)
                        {
                            ThumbRoot.Visibility = Visibility.Collapsed;
                        }
                    }

                    TitleLabel.Text   = GetFromLabel(message, title);
                    ServiceLabel.Text = document.FileName;
                    MessageLabel.Text = string.Empty;

                    if (!string.IsNullOrWhiteSpace(documentMedia.Caption))
                    {
                        ServiceLabel.Text += ", ";
                        MessageLabel.Text += documentMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                    }
                }
            }
            return(true);
        }
Esempio n. 10
0
        public PasscodePage()
        {
            InitializeComponent();

            _passcodeService = UnigramContainer.Current.ResolveType <IPasscodeService>();

            _applicationView = ApplicationView.GetForCurrentView();
            _applicationView.VisibleBoundsChanged += OnVisibleBoundsChanged;
            OnVisibleBoundsChanged(_applicationView, null);

            var user = InMemoryCacheService.Current.GetUser(SettingsHelper.UserId);

            if (user != null)
            {
                Photo.Source  = DefaultPhotoConverter.Convert(user, false) as ImageSource;
                FullName.Text = user.FullName;
            }
        }
Esempio n. 11
0
        private FrameworkElement ProcessSlideshow(PageBlockSlideshow block)
        {
            var element = new StackPanel {
                Style = Resources["BlockSlideshowStyle"] as Style
            };

            var items = new List <ImageView>();

            foreach (var item in block.PageBlocks)
            {
                if (item is PageBlockPhoto photoBlock)
                {
                    var image = new ImageView();
                    image.Source     = (ImageSource)DefaultPhotoConverter.Convert(photoBlock.Photo, true);
                    image.Constraint = photoBlock.Photo;

                    items.Add(image);
                }
                else if (item is PageBlockVideo videoBlock)
                {
                    var child = new ImageView();
                    child.Source     = (ImageSource)DefaultPhotoConverter.Convert(videoBlock.Video, true);
                    child.Constraint = videoBlock.Video;

                    items.Add(child);
                }
            }

            var flip = new FlipView();

            flip.ItemsSource = items;

            element.Children.Add(flip);

            var caption = ProcessText(block, true);

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

            return(element);
        }
Esempio n. 12
0
        private bool SetPhotoTemplate(TLMessage message, string title)
        {
            Visibility = Visibility.Visible;

            // 🖼

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = "Photo";
            MessageLabel.Text = string.Empty;

            if (message.Media is TLMessageMediaPhoto photoMedia)
            {
                if (photoMedia.HasTTLSeconds)
                {
                    if (ThumbRoot != null)
                    {
                        ThumbRoot.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    FindName(nameof(ThumbRoot));
                    if (ThumbRoot != null)
                    {
                        ThumbRoot.Visibility = Visibility.Visible;
                    }

                    ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                    ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(photoMedia, true);
                }

                if (!string.IsNullOrWhiteSpace(photoMedia.Caption))
                {
                    ServiceLabel.Text += ", ";
                    MessageLabel.Text += photoMedia.Caption.Replace("\r\n", "\n").Replace('\n', ' ');
                }
            }

            return(true);
        }
Esempio n. 13
0
        private bool SetServicePhotoTemplate(TLMessageService message, string title)
        {
            Visibility = Visibility.Visible;

            FindName(nameof(ThumbRoot));
            if (ThumbRoot != null)
            {
                ThumbRoot.Visibility = Visibility.Visible;
            }

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = string.Empty;
            MessageLabel.Text = ServiceHelper.Convert(message);

            var action = message.Action as TLMessageActionChatEditPhoto;

            if (action != null)
            {
                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(action.Photo, true);
            }

            return(true);
        }
Esempio n. 14
0
        private FrameworkElement ProcessEmbedPost(PageBlockEmbeddedPost block)
        {
            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, 0);

            var photo = block.AuthorPhoto;

            if (photo != null)
            {
                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);

                header.Children.Add(ellipse);
            }

            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(textAuthor);
            header.Children.Add(textDate);

            element.Children.Add(header);

            PageBlock        previousBlock   = null;
            FrameworkElement previousElement = null;

            foreach (var subBlock in block.PageBlocks)
            {
                var subLayout = ProcessBlock(subBlock);
                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);
        }
Esempio n. 15
0
        private FrameworkElement ProcessCollage(PageBlockCollage block)
        {
            var element = new StackPanel {
                Style = Resources["BlockCollageStyle"] as Style
            };

            var items = new List <ImageView>();

            foreach (var item in block.PageBlocks)
            {
                if (item is PageBlockPhoto photoBlock)
                {
                    //var galleryItem = new GalleryPhotoItem(photoBlock.Photo, photoBlock.Caption?.ToString());
                    //ViewModel.Gallery.Items.Add(galleryItem);

                    var child = new ImageView();
                    child.Source = (ImageSource)DefaultPhotoConverter.Convert(photoBlock.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 PageBlockVideo videoBlock)
                {
                    //var galleryItem = new GalleryDocumentItem(videoBlock.Video, videoBlock.Caption?.ToString());
                    //ViewModel.Gallery.Items.Add(galleryItem);

                    var child = new ImageView();
                    child.Source = (ImageSource)DefaultPhotoConverter.Convert(videoBlock.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(block, true);

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

            return(element);
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        private FrameworkElement GetPhoto(KeyValuePair <TLMessage, GroupedMessagePosition> position, GroupedMessages groupedMessages, double left, double top)
        {
            var margin = 1;

            var width  = 320d;
            var height = 420d;

            var element = new ContentControl
            {
                Content = position.Key,
                ContentTemplateSelector    = App.Current.Resources["MediaTemplateSelector"] as DataTemplateSelector,
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                VerticalContentAlignment   = VerticalAlignment.Stretch
            };

            element.DataContext         = position.Key;
            element.Width               = position.Value.Width / 800d * width - margin * 2;
            element.Height              = height * position.Value.Height - margin * 2;
            element.Margin              = new Thickness(left + margin, top + margin, margin, margin);
            element.HorizontalAlignment = HorizontalAlignment.Left;
            element.VerticalAlignment   = VerticalAlignment.Top;

            return(element);

            var photo = position.Key.GetPhoto();

            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 child = new ImageView();

            child.DataContext = position.Key;
            child.Source      = (ImageSource)DefaultPhotoConverter.Convert(photo, true);
            child.Click      += Click;
            child.Stretch     = Stretch.UniformToFill;
            child.HorizontalContentAlignment = HorizontalAlignment.Center;
            child.VerticalContentAlignment   = VerticalAlignment.Center;

            var transfer = new TransferButton();

            transfer.DataContext  = position.Key;
            transfer.Completed   += Completed;
            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.Name                = "Media";
            grid.DataContext         = position.Key;
            grid.Width               = position.Value.Width / 800d * width - margin * 2;
            grid.Height              = height * position.Value.Height - margin * 2;
            grid.Margin              = new Thickness(left + margin, top + margin, margin, margin);
            grid.HorizontalAlignment = HorizontalAlignment.Left;
            grid.VerticalAlignment   = VerticalAlignment.Top;
            grid.Children.Add(child);
            grid.Children.Add(transfer);

            return(grid);
        }