Reputation: 97
i cant bind an image to source from converter?
<!-- Works fine -->
<Image Grid.Row="0" Grid.Column="4" Grid.RowSpan="6" Margin="5">
<Image.Source>
C:\pictures\Becker.png
</Image.Source>
</Image>
<!-- Works not -->
<Image Source="{Binding ClientPicture, Converter={StaticResource clientpictureconv}, ConverterParameter={Binding ClientNumber}}"/>
In the converter i give back the hardcoded picture Uri (from the top). If i replace the Image with Textblock, the full uri is shown. But the picture in Image not.
What can i do?
Upvotes: 0
Views: 4813
Reputation: 10553
That's because Image.Source does not take a URI
object; it takes an ImageSource
object. Your converter should create one of those and pass it back. Put this in your converter, and it'll work:
return new BitmapImage(myUri);
Note that BitmapImage
is a type of ImageSource
.
Your first example works because XAML implicitly converts the URI string to an ImageSource for you. It can't do that when you explicitly pass back a URI object using your converter.
Upvotes: 4