I\'m creating an Image.Source
-String
binding in code like:
var newBinding = new System.Windows.Data.Binding()
{
Path = new Pr
System.Windows.Media.ImageSource has a TypeConverterAttribute
[TypeConverter(typeof(ImageSourceConverter))]
The binding will look for this and use the converter automatically.
If you look at the ImageSourceConverter
you can see what types it can convert from:
if (sourceType == typeof(string) ||
sourceType == typeof(Stream) ||
sourceType == typeof(Uri) ||
sourceType == typeof(byte[]))
{
return true;
}
In order to mimic this process, you must add a TypeConverterAttribute
on the Type of the property being bound to.
You can do this by 1. controlling the type, or 2. use the TypeDescriptor
at runtime to add the attribute. There's a question about this here.