[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}
请会的朋友指点一下。
|