1

Closed

Convention for binding an Image should be one-way

description

I have an Image named Photo and an VM property byte[] Photo.
If my XAML has Source="{Binding Path=Photo}", it works fine.
If I rely on the convention and remove the Source attribute from the XAML, I get the following trace output:

System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'System.Byte[]' and 'System.Windows.Media.ImageSource'. Consider using Converter property of Binding. BindingExpression:Path=Photo; DataItem='EditJobPhotoViewModel' (HashCode=20650019); target element is 'Image' (Name='Photo'); target property is 'Source' (type 'ImageSource')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='System.Byte[]' BindingExpression:Path=Photo; DataItem='EditJobPhotoViewModel' (HashCode=20650019); target element is 'Image' (Name='Photo'); target property is 'Source' (type 'ImageSource')
INFO: [2012-05-15T11:00:58.0079422-07:00] Binding Convention Applied: Element Photo.

Seems like Images should be one-way bindings.
Closed Aug 28, 2012 at 1:13 PM by EisenbergEffect
Not an issue.

comments

jbiddle61 wrote May 16, 2012 at 5:55 PM

Note that the convention binding works (defaults to one-way) if I remove the setter from the Photo property. There should be a better way to determine one-way vs two-way binding other that the presence of a setter on the property. As far as I know, Image controls cannot update their contents using the UI, only through code.

tibel wrote Jul 20, 2012 at 3:54 PM

You can make the setter "internal" or "protected", only "public" is interpreted as two-way binding.