IValueConverter problem
Can i pass complex type to converter as parameter? I have created one converter which basically converts byte array to BitmapImage. However when i pass the byte array as parameter in my binding expression, the parameter is passed as string i.e say my parameter name is PhotosByteArr and when i pass it as parameter to converter, i get the parame开发者_Python百科ter name PhotosByteArr and not the byte array.
This is my binding expression :-
<Image Source="{Binding ConverterParameter=PhotosByteArr, Converter={StaticResource byteArrToBitmap}}" Margin="0" Stretch="Fill"/>
PhotosByteArr is instance of byte[].
Any idea what can be wrong?
Thanks in advance :)
To make alpha-mouse's suggestion more explicit, your code should look like this:
<Image Source="{Binding PhotosByteArr, Converter={StaticResource byteArrToBitmap}}" Margin="0" Stretch="Fill"/>
(This is assuming that the byte array will be found from a path alone (i.e the DataContext should contain it))
The binding source will be passed to the converter in the value
object, the converter parameter offers another input channel if you need additional information. In this case that is not necessary.
I think this should be
{Binding ConverterParameter={Binding PhotosByteArr} ...
But I have the question to you. Why are you not writing
{Binding Path=PhotosByteArr ...
or just
{Binding PhotosByteArr ...
and then using value
argument of the Convert method?
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var array = (byte[])value;
...
}
精彩评论