In This Article

ImageConverter Class

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

[ValueConversion(typeof(string), typeof(Image))]
[ValueConversion(typeof(Uri), typeof(Image))]
[ValueConversion(typeof(BitmapSource), typeof(Image))]
public class ImageConverter : DependencyObject
Inheritance:
object object

Remarks

This converter expects the source value to be a System.Uri, a URI string, or a 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 string before the Image is created.

Constructors

ImageConverter()

Initializes an instance of the class.

public ImageConverter()

Properties

Height

Gets or sets the target height of the image.

public double Height { get; set; }

Property Value

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

string:

The URI prefix.

Width

Gets or sets the target width of the image.

public double Width { get; set; }

Property Value

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 string or System.Uri, or the specified BitmapSource to an Image.

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

The value produced by the binding source.

targetType Type

The type of the binding target property.

parameter object

The converter parameter to use.

culture CultureInfo

The culture to use in the converter.

Returns

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 object

Not used.

targetType Type

Not used.

parameter object

Not used.

culture CultureInfo

Not used.

Returns

object:

null.

CreateImage(ImageSource)

Creates an Image control to display the specified ImageSource.

protected virtual Image CreateImage(ImageSource imageSource)
Parameter Type Description
imageSource ImageSource

The 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