开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 2639|回复: 0

GridControl cells显示图片报错

[复制链接]

0

精华

596

贡献

57

赞扬

赞助者组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
27
软币
230
在线时间
21 小时
注册时间
2013-7-18
发表于 2017-5-4 13:02:25 | 显示全部楼层 |阅读模式
[XML] 纯文本查看 复制代码
 <dxg:GridColumn FieldName="Member" IsSmart="True" ReadOnly="True" HorizontalHeaderContentAlignment="Center">
                    <dxg:GridColumn.DisplayTemplate>
                        <ControlTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Name="PART_Editor" Height="18" Width="18" HorizontalAlignment="Left" Source="{Binding Path = RowData.Row.Level, ConverterParameter=GridControl, Converter={StaticResource myMemberConverter}, Mode=OneWay}" Stretch="Fill" VerticalAlignment="Top"/>
                                <TextBlock Text="{Binding Path=RowData.Row.Member}" />
                            </StackPanel>
                        </ControlTemplate>
                    </dxg:GridColumn.DisplayTemplate>
                </dxg:GridColumn>



[C#] 纯文本查看 复制代码
using System;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace Sundial.WPF.Controls
{
   [ValueConversion(typeof(Logger.Levels), typeof(Image))]
    public class MemberToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Image image = new Image();
            if (parameter.ToString() == "GridControl")
            {
                //BitmapFrame bf =  BitmapFrame.Create(new Uri("pack://application:,,,/Sundial.WPF.Controls.Vi;component/Logger/Images/Debug.18x18.png", UriKind.RelativeOrAbsolute));
                Uri myUri = new Uri("pack://application:,,,/Sundial.WPF.Controls.Vi;component/Logger/Images/Debug.18x18.png", UriKind.RelativeOrAbsolute);
                var decoder = new PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                var bitmapFrame = decoder.Frames[0];

                //if ((Logger.Levels)Enum.Parse(typeof(Logger.Levels), value.ToString()) == Logger.Levels.WARN)
                // bi = new BitmapImage(new Uri("Vi/Logger/Images/Warn.18x18.png", UriKind.RelativeOrAbsolute));

                //if ((Logger.Levels)Enum.Parse(typeof(Logger.Levels), value.ToString()) == Logger.Levels.INFO)
                //bi = new BitmapImage(new Uri("pack://application:,,,/Sundial.WPF.Controls.Vi;component/Logger/Images/Info.18x18.png", UriKind.RelativeOrAbsolute));
                //if ((Logger.Levels)Enum.Parse(typeof(Logger.Levels), value.ToString()) == Logger.Levels.FATAL)
                // bi = new BitmapImage(new Uri("pack://application:,,,/Sundial.WPF.Controls.Vi;component/Logger/Images/Fatal.18x18.png", UriKind.RelativeOrAbsolute));
                //if ((Logger.Levels)Enum.Parse(typeof(Logger.Levels), value.ToString()) == Logger.Levels.ERROR)
                // bi = new BitmapImage(new Uri("pack://application:,,,/Sundial.WPF.Controls.Vi;component/Logger/Images/Error.18x18.png", UriKind.RelativeOrAbsolute));

                image.Source = bitmapFrame;

            }

            return image;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
    



以上是XAML和C#代码,运行调试报错:-        Metadata    {System.Windows.Media.Imaging.BitmapMetadata}   +        InnerException    {"位图编解码器不支持位图属性。 (异常来自 HRESULT:0x88982F41)"}    System.Exception {System.Runtime.InteropServices.COMException}
请会的朋友指点一下。

png图片

png图片
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-3-19 10:39

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表