public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var items = new ObservableCollection <Inline>();
            var image = value as IMessageImage;

            if (image == null || string.IsNullOrEmpty(image.Url))
            {
                return(items);//nullを返したらDataGridでVirtualizationModeをRecyclingにしている場合に他の画像が表示されてしまう
            }
            var inline = ConverterTools.Convert(image);

            items.Add(inline);
            return(items);
        }
示例#2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var collection = new ObservableCollection <Inline>();
            var items      = value as IEnumerable <IMessagePart>;

            if (items == null)
            {
                return(collection);
            }
            IMessagePart before = null;

            foreach (IMessagePart item in items)
            {
                if (item is IMessageText text)
                {
                    collection.Add(new Run(text.Text));
                }
                else if (item is IMessageLink link)
                {
                    collection.Add(new Hyperlink(new Run(link.Text))
                    {
                        NavigateUri = new Uri(link.Url)
                    });
                }
                else if (item is IMessageImage remoteImage)
                {
                    var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                else if (item is IMessageImagePortion ico)
                {
                    if (before is IMessageText)
                    {
                        collection.Add(new Run(" "));
                    }

                    var uiContainer = ConverterTools.ImagePortion2UiContainer(ico);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                before = item;
            }
            return(collection);
        }
        public static InlineUIContainer ImagePortion2UiContainer(IMessageImagePortion ico)
        {
            var bitmap      = new System.Drawing.Bitmap(ico.Image);
            var rectangle   = new System.Drawing.Rectangle(ico.SrcX, ico.SrcY, ico.SrcWidth, ico.SrcHeight);
            var cropped     = bitmap.Clone(rectangle, bitmap.PixelFormat);
            var bitmapImage = ConverterTools.ConvertFromBitmap(cropped, System.Drawing.Imaging.ImageFormat.Png);
            var image       = new Image()
            {
                Width  = ico.Width,
                Height = ico.Height,
                Source = bitmapImage,
            };

            if (!string.IsNullOrEmpty(ico.Alt))
            {
                image.ToolTip = ico.Alt;
            }
            return(new InlineUIContainer(image));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var collection = new ObservableCollection <Inline>();
            var items      = value as IEnumerable <IMessagePart>;

            if (items == null)
            {
                return(collection);
            }
            IMessagePart before = null;

            foreach (IMessagePart item in items)
            {
                if (item is IMessageText text)
                {
                    collection.Add(new Run(text.Text));
                }
                else if (item is IMessageLink link)
                {
                    collection.Add(new Hyperlink(new Run(link.Text))
                    {
                        NavigateUri = new Uri(link.Url)
                    });
                }
                else if (item is IMessageImage remoteImage)
                {
                    var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                else if (item is IMessageImagePortion ico)
                {
                    if (before is IMessageText)
                    {
                        collection.Add(new Run(" "));
                    }

                    var uiContainer = ConverterTools.ImagePortion2UiContainer(ico);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                else if (item is IMessageRemoteSvg remoteSvg)
                {
                    try
                    {
                        var box = new SharpVectors.Converters.SvgViewbox();
                        box.BeginInit();
                        box.Source = new Uri(remoteSvg.Url);
                        box.EndInit();
                        if (remoteSvg.Width.HasValue)
                        {
                            box.Width = remoteSvg.Width.Value;
                        }
                        if (remoteSvg.Height.HasValue)
                        {
                            box.Height = remoteSvg.Height.Value;
                        }
                        var inline = new InlineUIContainer(box);
                        collection.Add(inline);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                else
                {
                }
                before = item;
            }
            return(collection);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var collection = new ObservableCollection <Inline>();
            var items      = value as IEnumerable <IMessagePart>;

            if (items == null)
            {
                return(collection);
            }
            IMessagePart before = null;

            foreach (IMessagePart item in items)
            {
                if (item is IMessageText text)
                {
                    collection.Add(new Run(text.Text));
                }
                else if (item is IMessageImage remoteImage)
                {
                    var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                else if (item is IMessageImagePortion ico)
                {
                    if (before is IMessageText)
                    {
                        collection.Add(new Run(" "));
                    }

                    var uiContainer = ConverterTools.ImagePortion2UiContainer(ico);
                    if (uiContainer != null)
                    {
                        collection.Add(uiContainer);
                    }
                }
                else if (item is IMessageSvg svg)
                {
                    var box = new SharpVectors.Converters.SvgViewbox();
                    box.SvgSource = svg.Data;
                    //box.SvgSource = @"<svg viewBox=""0 0 16 16"" preserveAspectRatio=""xMidYMid meet"" focusable=""false"" class=""style-scope yt-icon"" style=""pointer-events: none; display: block; width: 100%; height: 100%;"" xmlns=""http://www.w3.org/2000/svg"" version=""1.1""><g class=""style-scope yt-icon""><path d=""M9.64589146,7.05569719 C9.83346524,6.562372 9.93617022,6.02722257 9.93617022,5.46808511 C9.93617022,3.00042984 7.93574038,1 5.46808511,1 C4.90894765,1 4.37379823,1.10270499 3.88047304,1.29027875 L6.95744681,4.36725249 L4.36725255,6.95744681 L1.29027875,3.88047305 C1.10270498,4.37379824 1,4.90894766 1,5.46808511 C1,7.93574038 3.00042984,9.93617022 5.46808511,9.93617022 C6.02722256,9.93617022 6.56237198,9.83346524 7.05569716,9.64589147 L12.4098057,15 L15,12.4098057 L9.64589146,7.05569719 Z"" class=""style-scope yt-icon""></path></g></svg>";
                    if (svg.Height.HasValue)
                    {
                        box.Height = svg.Height.Value;
                    }
                    if (svg.Width.HasValue)
                    {
                        box.Width = svg.Width.Value;
                    }
                    var inline = new InlineUIContainer(box);
                    collection.Add(inline);
                }
                else
                {
                }
                before = item;
            }
            return(collection);
        }