public class ImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var imagePath = new BitmapImage(new Uri("/Lithography;component/Themes/Images/action2.png", UriKind.RelativeOrAbsolute));
var ret = (ActionType)value;
if (ret == ActionType.ParallelAndWaitForActionToBeCompleted)
{
imagePath = new BitmapImage(new Uri("/Lithography;component/Themes/Images/parallel2.png", UriKind.RelativeOrAbsolute));
}
else if (ret == ActionType.Sequence)
{
imagePath = new BitmapImage(new Uri("/Lithography;component/Themes/Images/order2.png", UriKind.RelativeOrAbsolute));
}
return imagePath;
return null;
}
catch (Exception)
{
// 可以返回一个默认图片或者 null
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
和在xaml中使用Source差不多:
<Image
Width="20"
Height="15"
VerticalAlignment="Center"
Source="/Lithography;component/Themes/Images/MoveTo.png" />
-----------------------------------------------------------------------
图片看起来有锯齿可以在Image控件中这样设置:
RenderOptions.BitmapScalingMode="HighQuality"
RenderOptions.EdgeMode="Aliased"
SnapsToDevicePixels="True"
前后效果:
是好了一点。