private void MessageForwardedMessageControl_OnSizeChanged(object sender, SizeChangedEventArgs e) { if (Message?.MessageContent?.Attachments?.OfType <VkPhotoAttachment>().Count() > 0) { if (_lastSize != e.NewSize) { PhotosControl.MaxWidth = Math.Max(180, e.NewSize.Width + 5); if (PhotosControl.Children.Count > 0) { PhotoSpacier.Calculate(PhotosControl); } } } _lastSize = e.NewSize; }
private void UpdateContent() { AttachmentsPanel.Children.Clear(); PhotosControl.Children.Clear(); if (Message != null) { this.Foreground = (Brush)(Message.MessageContent.IsOut ? Application.Current.Resources["ConversationOutboxMessageForegroundBrush"] : Application.Current.Resources["ConversationInboxMessageForegroundBrush"]); BodyTextBlock.Visibility = !string.IsNullOrEmpty(Message.MessageContent.Body) ? Visibility.Visible : Visibility.Collapsed; TextBlockExtension.SetFormattedText(BodyTextBlock, Message.MessageContent.Body); bool isOut = Message.MessageContent.IsOut; TextBlockExtension.SetHyperlinkForeground(BodyTextBlock, (Brush)(isOut ? Application.Current.Resources["ConversationOutboxHyperlinkForegroundBrush"] : Application.Current.Resources["ConversationInboxHyperlinkForegroundBrush"])); if (Message.MessageContent.IsOut) { BodyTextBlock.SelectionHighlightColor = (SolidColorBrush)Application.Current.Resources["ChatMessageOutHighlightingTextBrush"]; } else { BodyTextBlock.SelectionHighlightColor = (SolidColorBrush)Application.Current.Resources["SystemControlHighlightAccentBrush"]; } if (!Message.MessageContent.Attachments.IsNullOrEmpty()) { AttachmentsPanel.Visibility = Visibility.Visible; if (Message.MessageContent.Attachments.Any(a => a is VkPhotoAttachment)) { PhotosControl.Visibility = Visibility.Visible; foreach (var attachment in Message.MessageContent.Attachments.OfType <VkPhotoAttachment>()) { var photo = (VkPhotoAttachment)attachment; var button = new Button(); button.Style = (Style)Application.Current.Resources["SimpleButtonStyle"]; var image = new Image(); image.Stretch = Stretch.UniformToFill; button.MaxWidth = photo.Width; button.MaxHeight = photo.Height; image.AddHandler(TappedEvent, new TappedEventHandler(OnImageTapped), false); button.Content = image; var sourceUrl = photo.SourceXBig ?? photo.Source ?? photo.SourceSmall; if (sourceUrl != null) { image.Source = new BitmapImage(new Uri(sourceUrl)); } PhotosControl.Children.Add(button); } if (PhotosControl.Children.Count > 0) { PhotoSpacier.Calculate(PhotosControl); } } else { PhotosControl.Visibility = Visibility.Collapsed; } var attachments = Message.MessageContent.Attachments.Where(a => !(a is VkPhotoAttachment)).ToList(); var i = 0; foreach (var attachment in attachments) { if (attachment is VkStickerAttachment) { var sticker = (VkStickerAttachment)attachment; var image = new Image(); image.Stretch = Stretch.Uniform; var thumbSize = CalcThumbnailSize(sticker.Width, sticker.Height, 200, 200); image.Width = thumbSize.Width; image.Height = thumbSize.Height; var sourceUrl = sticker.Photo256; if (sourceUrl != null) { image.Source = new BitmapImage(new Uri(sourceUrl)); } AttachmentsPanel.Children.Add(image); } else if (attachment is VkGiftAttachment) { var gift = (VkGiftAttachment)attachment; var image = new Image(); image.Stretch = Stretch.UniformToFill; image.Width = 200; image.Height = 200; var sourceUrl = gift.Thumb256; if (sourceUrl != null) { image.Source = new BitmapImage(new Uri(sourceUrl)); } AttachmentsPanel.Children.Add(image); } else if (attachment is VkAudioAttachment) { var audio = (VkAudioAttachment)attachment; var audioControl = new MessageAudioControl(); audioControl.Margin = new Thickness(0, 0, 0, i < attachments.Count - 1 ? 5 : 0); audioControl.Audio = audio; AttachmentsPanel.Children.Add(audioControl); } else if (attachment is VkLinkAttachment) { var link = (VkLinkAttachment)attachment; var linkControl = new MessageLinkControl(link); AttachmentsPanel.Children.Add(linkControl); } else if (attachment is VkDocumentAttachment) { var document = (VkDocumentAttachment)attachment; var documentControl = new MessageDocumentControl(document); documentControl.Margin = new Thickness(0, 0, 0, i < attachments.Count - 1 ? 5 : 0); AttachmentsPanel.Children.Add(documentControl); } else if (attachment is VkVideoAttachment) { var video = (VkVideoAttachment)attachment; var videoControl = new MessageVideoControl(video); videoControl.Margin = new Thickness(0, 0, 0, i < attachments.Count - 1 ? 5 : 0); AttachmentsPanel.Children.Add(videoControl); } else if (attachment is VkWallPostAttachment) { var wallPost = (VkWallPostAttachment)attachment; var wallPostControl = new MessageWallPostControl(wallPost); AttachmentsPanel.Children.Add(wallPostControl); } i++; } } else if (Message.MessageContent.Geo != null) { AttachmentsPanel.Visibility = Visibility.Visible; var url = MapHelper.GetMapPreviewForCoords(Message.MessageContent.Geo.Latitude, Message.MessageContent.Geo.Longitude); var button = new Button(); button.Style = (Style)Application.Current.Resources["SimpleButtonStyle"]; var image = new Image(); image.Stretch = Stretch.UniformToFill; button.Width = 200; button.Height = 200; image.Tag = Message.MessageContent.Geo; image.Source = new BitmapImage(new Uri(url)); button.Content = image; image.AddHandler(TappedEvent, new TappedEventHandler(OnMapImageTapped), false); AttachmentsPanel.Children.Add(button); } else if (!Message.MessageContent.ForwardMessages.IsNullOrEmpty()) { AttachmentsPanel.Visibility = Visibility.Visible; foreach (var forwardMessage in Message.MessageContent.ForwardMessages) { var forwardMessageControl = new MessageForwardedMessageControl(); forwardMessageControl.Message = new Message(forwardMessage, new VkProfile()); forwardMessageControl.Margin = new Thickness(5, 0, 0, 0); forwardMessageControl.SetBinding(ForegroundProperty, new Binding() { Path = new PropertyPath("Foreground"), Source = this }); AttachmentsPanel.Children.Add(forwardMessageControl); } } else { AttachmentsPanel.Visibility = Visibility.Collapsed; } if (Message.IsNew) { Message.IsNew = false; var s = (Storyboard)Resources["LoadAnim"]; s.Stop(); Storyboard.SetTarget(s, this.GetVisualAncestors().OfType <ListViewItem>().FirstOrDefault()); s.Begin(); } } }