Special behavior of MultiBinding vs Binding when specifying ImageSource

I encountered special behavior when binding to a property Source Imageusing a converter.

It seems that if I use simple Bindingc IValueConverter, which returns a string corresponding to the relative path to the image, everything is fine and the image is displayed.

On the other hand, if I use MultiBindingc IMultiValueConverter, which returns the same string, the binding does not work, and this error message is displayed in the VS2010 output window:

System.Windows.Data error: 5: The value generated by BindingExpression is not valid for the target property; Value = '' MultiBindingExpression: the target element is an "Image" (Name = ''); target is "Source" (type "ImageSource")

I found out that for this I cannot return a simple string (and not even Uri). Instead, I have to create an ImageSource in my converter (a BitmapImage) and return it.

Do you know why this strange behavior happens? Is this difference between Bindingand known MultiBinding, or is this a mistake?

I found an https://stackoverflow.com/a/3129609/ which can relate to this, where Alvin posted a comment about the time when the binding is allowed:

, MultiBinding AFTER TextBlock () TextBlok - Avlin

, , .

!

+3
2

, , , , , , MultiBindings, .

+1

( !)

XAML:

<MediaElement LoadedBehavior="Play" Stretch="UniformToFill">
    <MediaElement.Source>
        <MultiBinding Converter="{StaticResource ActionMedia_Converter}"> 
            <Binding Path="HomeW_Background_FileName" />
            <Binding Path="HomeW_Background_FileType" />
        </MultiBinding>
    </MediaElement.Source>
</MediaElement>
Hide result

:

Public Class ActionMedia_Converter
	Implements IMultiValueConverter

	Public Function Convert(values As Object(), TargetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IMultiValueConverter.Convert
		Dim ImageSource As String

		ImageSource = String.Concat(values(0), ".", values(1))

		Dim MyUri = New System.Uri(ImageSource)
		
		Return MyUri

	End Function

	Public Function ConvertBack(values As Object, targetTypes As Type(), parameter As Object, culture As CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
		Return Binding.DoNothing
	End Function

End Class
Hide result
0

All Articles