In This Article

ImageConverter Class

Represents a value converter that returns a new Image instance created using a specified URI or System.Windows.Media.Imaging.BitmapSource.

[ValueConversion(typeof(string), typeof(Image))]
[ValueConversion(typeof(Uri), typeof(Image))]
[ValueConversion(typeof(BitmapSource), typeof(Image))]
public class ImageConverter : DependencyObject, IValueConverter
Inheritance:
System.Object System.Windows.Threading.DispatcherObject System.Windows.DependencyObject Object

Remarks

This converter expects the source value to be a System.Uri, a URI System.String, or a System.Windows.Media.Imaging.BitmapSource that can be used to create a new Image instance. A prefix can be defined in UriPrefix which will be prepended to all source values of type System.String before the Image is created.

Constructors

ImageConverter()

public ImageConverter()

Properties

Height

Gets or sets the target height of the image.

public double Height { get; set; }

Property Value

System.Double:

The target height of the image. The default value is NaN, which won't set a target height on the Image control that is created.

ImageProvider

Gets or sets the optional ImageProvider to use with image sources created by the converter.

public ImageProvider ImageProvider { get; set; }

Property Value

ImageProvider:

The optional ImageProvider to use with image sources created by the converter. The default value is null, meaning use the static default ImageProvider.

UriPrefix

Gets or sets the URI prefix that should be prepended to all values converted by this object. This is a dependency property.

public string UriPrefix { get; set; }

Property Value

System.String:

The URI prefix.

Width

Gets or sets the target width of the image.

public double Width { get; set; }

Property Value

System.Double:

The target width of the image. The default value is NaN, which won't set a target width on the Image control that is created.

Methods

Convert(Object, Type, Object, CultureInfo)

Converts the specified URI, in the form of a System.String or System.Uri, or the specified System.Windows.Media.Imaging.BitmapSource to an Image.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Parameter Type Description
value System.Object

The value produced by the binding source.

targetType System.Type

The type of the binding target property.

parameter System.Object

The converter parameter to use.

culture System.Globalization.CultureInfo

The culture to use in the converter.

Returns

System.Object:

An Image associated with the specified URI.

Remarks

See ImageConverter for more information on the expected source values.

ConvertBack(Object, Type, Object, CultureInfo)

This method always returns null and should not be used.

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Parameter Type Description
value System.Object

Not used.

targetType System.Type

Not used.

parameter System.Object

Not used.

culture System.Globalization.CultureInfo

Not used.

Returns

System.Object:

null.

CreateImage(ImageSource)

Creates an Image control to display the specified System.Windows.Media.ImageSource.

protected virtual Image CreateImage(ImageSource imageSource)
Parameter Type Description
imageSource System.Windows.Media.ImageSource

The System.Windows.Media.ImageSource to examine.

Returns

Image:

The Image that was created.

Remarks

The default implementation of this method creates a DynamicImage instance.

Fields

HeightProperty

Identifies the Height dependency property. This field is read-only.

public static readonly DependencyProperty HeightProperty

ImageProviderProperty

Identifies the ImageProvider dependency property. This field is read-only.

public static readonly DependencyProperty ImageProviderProperty

UriPrefixProperty

Identifies the UriPrefix dependency property. This field is read-only.

public static readonly DependencyProperty UriPrefixProperty

WidthProperty

Identifies the Width dependency property. This field is read-only.

public static readonly DependencyProperty WidthProperty

Inherited Members

  • System.Object.ToString()
  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object, System.Object)
  • System.Object.ReferenceEquals(System.Object, System.Object)
  • System.Object.GetHashCode()
  • System.Object.GetType()
  • System.Object.MemberwiseClone()