MultiBinding的特殊行为VS指定的ImageSource当绑定

问题描述:

我绑定到图像的来源属性时,碰到了一个特殊的行为,使用转换器。

I ran into a special behavior when binding to the Source property of an Image, using a converter.

看来,如果我用一个简单的绑定的IValueConverter 返回字符串correpsonding为相对路径到图像,一切正常,并显示图像。

It appears that if I use a simple Binding with a IValueConverter that returns a string correpsonding to a relative path to the image, everything is OK and the image is displayed.

在另一方面,如果我用一个 MultiBinding IMultiValueConverter 返回相同的字符串,绑定不工作,并显示在VS2010输出窗口此错误消息:

On the other hand, if I use a MultiBinding with a IMultiValueConverter that returns the same string, the binding doesn't work and this error message is displayed in VS2010 output window :

System.Windows.Data错误:5:BindingEx pression生产值是不是有效的目标属性;值=''MultiBindingEx pression:目标元素是'图像'(名称='');目标属性是源(类型'的ImageSource')

System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' MultiBindingExpression:target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource')

我发现这个工作,我不能返回一个简单的字符串(而不是连乌里)。我不是在我的转换器来创建一个ImageSource的(A 的BitmapImage ,其实)并返回。

I found out that for this to work, I can't return a simple string (and not even a Uri). I instead have to create a ImageSource in my converter (a BitmapImage, in fact) and return it.

你知道为什么这种奇怪的行为发生?这是之间的已知差异绑定 MultiBinding ,或者是一个错误吗?

Do you know why this strange behavior happens? Is this a known difference between Binding and MultiBinding, or is it a bug?

我发现可能会涉及到这个计算器的另一个话题,其中阿尔文贴当绑定都解决了时间评论:

I found another * topic that may relate to this, where Alvin posted a comment about the time when the binding are resolved :

我觉得MultiBinding作出后TextBlock的渲染,以及(单)绑定之前TextBlok渲染 - Avlin

I think that MultiBinding is made AFTER TextBlock rendering, and (single)Binding BEFORE TextBlok rendering – Avlin

要说明这个问题,我写了一个小的项目,你可以下载和测试一>

To Illustrate this problem, I wrote a small project that you can download and test.

感谢您的任何见解!

我会认为这是由设计,但可以肯定,你需要问的开发者之一,所不同的仅仅是没有的应用于由返回的值nofollow的>类型转换 MultiBindings ,对人们的行程相当频繁。

I would assume that this is by design but to be sure you would need to ask one of the developers, the difference is just that no type conversion is applied to the values returned by MultiBindings, people trip on that fairly often.