internal Row(User user, Role role) { User = user; Role = role; LabelUserName.Content = User.UserName; LabelUserName.HorizontalContentAlignment = HorizontalAlignment.Left; LabelContextHeader.Content = User.UserName; ImageAvatar.Height = 28; ImageAvatar.Width = 28; SetDock(LabelUserName, Dock.Left); SetDock(ImageAvatar, Dock.Left); Children.Add(ImageAvatar); Children.Add(LabelUserName); // UserContextMenu.Items.Add(LabelContextHeader); UserContextMenu.Items.Add(MenuItemChangeRole); UserContextMenu.Items.Add(MenuItemKick); EventTrigger.RoutedEvent = Button.ClickEvent; LabelUserName.ContextMenu = UserContextMenu; LabelUserName.Triggers.Add(EventTrigger); LabelUserName.MouseEnter += (o, e) => { LabelUserName.Background = Brushes.DarkGray; }; LabelUserName.MouseLeave += (o, e) => { LabelUserName.Background = Brushes.Transparent; }; MenuItemKick.Click += (o, e) => { KickUser?.Invoke(this, new KickUserEventArgs(User)); }; MenuItemChangeRole.Click += (o, e) => { ChangeUserRole?.Invoke(this, new ChangeUserRoleEventArgs(User, Role)); }; LabelUserName.MouseUp += (o, e) => { LabelUserName.ContextMenu.IsOpen = true; }; Application.Current.Dispatcher.Invoke(async() => { await ImageResolver.DownloadUserImageAsync(user.ImageName, bitmap => { ImageAvatar.Source = bitmap; }); }); }
/// <summary> /// Init control with given MRU item /// </summary> /// <param name="item">MRU item to show on control</param> /// <param name="localization">localization instance</param> /// <param name="imagePathForItem">image for menu item (currently not supported)</param> public void Initialize(MRUItem item, MRUGuiItemLocalization localization, string imagePathForItem) { this.item = item; UpdateAppearance(); this.Image = ImageResolver.GetImageForItem(item, imagePathForItem); // subscribe to events this.Click += MRUItemMenu_Click; }
private async void Page_Loaded(object sender, RoutedEventArgs e) { TextBoxUserName.Text = Inventory.CurrentUser.UserName; TextBoxEmail.Text = Inventory.CurrentUser.Email; if (Inventory.CurrentUser.ImageName != null) { await ImageResolver.DownloadUserImageAsync(Inventory.CurrentUser.ImageName, bitmap => { UserImage.Source = bitmap; }); } }
private StatusModel(TwitterStatus status) { Status = status; Task.Run(() => { foreach (var image in ImageResolver.ResolveImages(status)) { _thumbnails.Add(new ThumbnailImage(image)); } }); }
internal async Task MakeImageAsync() { Image.Height = 28; Image.Width = 28; if (Message.User.ImageName == null) { return; } await ImageResolver.DownloadUserImageAsync(Message.User.ImageName, bitmap => { Image.Source = bitmap; }); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { if (Inventory.CurrentUser == null) { return; } LabelUserName.Content = Inventory.CurrentUser.UserName; LabelEmail.Content = Inventory.CurrentUser.Email; if (Inventory.CurrentUser.ImageName != null) { await ImageResolver.DownloadUserImageAsync(Inventory.CurrentUser.ImageName, bitmap => { UserImage.Source = bitmap; }); } }
private void ButtonUpload_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.png;*.jpg;*.jpeg;*.bmp) | *.png;*.jpg;*.jpeg;*.bmp"; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == true) { BitmapImage bitmapImage = ImageResolver.GetBitmapFromLocalFile(openFileDialog.FileName); if (bitmapImage == null) { MessageBox.Show("File doesn't exist or broken."); return; } UserImage.Source = bitmapImage; newUserImageFileName = openFileDialog.FileName; } }
private StatusModel(TwitterStatus status) { this.Status = status; ImageResolver.Resolve(status.GetEntityAidedText(true)) .Aggregate(new List <Tuple <Uri, Uri> >(), (l, i) => { l.Add(i); return(l); }) .Finally(() => { var subj = Interlocked.Exchange(ref this._imagesSubject, null); lock (subj) { subj.OnCompleted(); // WE SHOULD NOT CALL Dispose METHOD !!! // http://stackoverflow.com/questions/16540853/why-does-subjectt-dispose-does-not-dispose-current-suscriptions // subj.Dispose(); } }) .Subscribe(l => this.Images = l); }
/// <summary> /// Renders an image element. /// </summary> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> protected override async void RenderImage(ImageInline element, IRenderContext context) { var localContext = context as InlineRenderContext; if (localContext == null) { throw new RenderContextIncorrectException(); } var inlineCollection = localContext.InlineCollection; var placeholder = InternalRenderTextRun(new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); var resolvedImage = await ImageResolver.ResolveImageAsync(element.RenderUrl, element.Tooltip); // if image can not be resolved we have to return if (resolvedImage == null) { return; } var image = new Image { Source = resolvedImage, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Stretch = ImageStretch }; HyperlinkButton hyperlinkButton = new HyperlinkButton() { Content = image }; var viewbox = new Viewbox { Child = hyperlinkButton, StretchDirection = Windows.UI.Xaml.Controls.StretchDirection.DownOnly }; viewbox.PointerWheelChanged += Preventative_PointerWheelChanged; var scrollViewer = new ScrollViewer { Content = viewbox, VerticalScrollMode = ScrollMode.Disabled, VerticalScrollBarVisibility = ScrollBarVisibility.Disabled }; var imageContainer = new InlineUIContainer() { Child = scrollViewer }; bool ishyperlink = false; if (element.RenderUrl != element.Url) { ishyperlink = true; } LinkRegister.RegisterNewHyperLink(image, element.Url, ishyperlink); if (ImageMaxHeight > 0) { viewbox.MaxHeight = ImageMaxHeight; } if (ImageMaxWidth > 0) { viewbox.MaxWidth = ImageMaxWidth; } if (element.ImageWidth > 0) { image.Width = element.ImageWidth; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0) { if (element.ImageWidth == 0) { image.Width = element.ImageHeight; } image.Height = element.ImageHeight; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0 && element.ImageWidth > 0) { image.Stretch = Stretch.Fill; } // If image size is given then scroll to view overflown part if (element.ImageHeight > 0 || element.ImageWidth > 0) { scrollViewer.HorizontalScrollMode = ScrollMode.Auto; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; } // Else resize the image else { scrollViewer.HorizontalScrollMode = ScrollMode.Disabled; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; } ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { var placeholderIndex = inlineCollection.IndexOf(placeholder); inlineCollection.Remove(placeholder); inlineCollection.Insert(placeholderIndex, imageContainer); } catch { // Ignore error } }
/// <summary> /// Renders an image element. /// </summary> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> protected override async void RenderImage(ImageInline element, IRenderContext context) { var localContext = context as InlineRenderContext; if (localContext == null) { throw new RenderContextIncorrectException(); } var inlineCollection = localContext.InlineCollection; var placeholder = InternalRenderTextRun(new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); var resolvedImage = await ImageResolver.ResolveImageAsync(element.Url, element.Tooltip); // if image can not be resolved we have to return if (resolvedImage == null) { return; } var image = new Image(); var imageContainer = new InlineUIContainer() { Child = image }; LinkRegister.RegisterNewHyperLink(image, element.Url); image.Source = resolvedImage; image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Stretch = ImageStretch; if (element.ImageWidth > 0) { image.Width = element.ImageWidth; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0) { if (element.ImageWidth == 0) { image.Width = element.ImageHeight; } image.Height = element.ImageHeight; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0 && element.ImageWidth > 0) { image.Stretch = Stretch.Fill; } ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { var placeholderIndex = inlineCollection.IndexOf(placeholder); inlineCollection.Remove(placeholder); inlineCollection.Insert(placeholderIndex, imageContainer); } catch { // Ignore error } }
/// <summary> /// Renders an image element. /// </summary> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> protected override async void RenderImage(ImageInline element, IRenderContext context) { if (!(context is InlineRenderContext localContext)) { throw new RenderContextIncorrectException(); } var inlineCollection = localContext.InlineCollection; var placeholder = InternalRenderTextRun(new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); var resolvedImage = await ImageResolver.ResolveImageAsync(element.RenderUrl, element.Tooltip); if (resolvedImage == null) { return; } var image = new Image { Source = resolvedImage, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Stretch = ImageStretch }; HyperlinkButton hyperlinkButton = new HyperlinkButton() { Content = image }; var viewbox = new Viewbox { Child = hyperlinkButton, StretchDirection = StretchDirection.DownOnly }; var imageContainer = new InlineUIContainer() { Child = viewbox }; bool ishyperlink = false; if (element.RenderUrl != element.Url) { ishyperlink = true; } LinkRegister.RegisterNewHyperLink(hyperlinkButton, element.Url, ishyperlink); if (ImageMaxHeight > 0) { viewbox.MaxHeight = ImageMaxHeight; } if (ImageMaxWidth > 0) { viewbox.MaxWidth = ImageMaxWidth; } if (element.ImageWidth > 0) { image.Width = element.ImageWidth; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0) { if (element.ImageWidth == 0) { image.Width = element.ImageHeight; } image.Height = element.ImageHeight; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0 && element.ImageWidth > 0) { image.Stretch = Stretch.Fill; } ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { inlineCollection.InsertAfter(placeholder, imageContainer); inlineCollection.Remove(placeholder); } catch { } }