show image in silverlight (4) grid
i'm new at silverlight and i'm experimenting with it right now. I have the following xaml:
<Grid Background="#FF06EFEF" Width="280">
<Border BorderBrush="#FF000000" BorderThickness="1" Width="auto" Height="90">
<StackPanel>
<TextBlock x:Name="denaam" TextWrapping="Wrap" Width="auto" Text="{Binding Naam}" />
<Image x:Name="MyImage" Width="40" Height="40" Source="{Binding Foto}"></Image>
<TextBlock x:Name="denaam2" TextWrapping="Wrap" Width="auto" Text="{Binding Foto}" />
</StackPanel>
</Border>
</Grid>
as you can see the textblocks are bound to two properties of an object (the the props Naam and Foto)
Now both Naam and Foto are showing in the textblock, but the Foto only as text (because it is a textblock)
Now i want the Foto (which holds a url like this 'http://www.megomuseum.com/teevee/images/robot.jpg') to be the source of the Image, so开发者_运维百科 the picture shows up.
Hope i made myself clear :)
So the data is binding because the props are showed, but the image controls shows nothing.
Take a look to Silverlight 2 - Binding Images to Uri's post. There you will find how to correctly bind url to image.
Binding to Image source also will help you.
The binding type for Source in an Image needs to be an ImageSource type. A Bitmap property is the usual way of doing this, or use a value convertor that takes a string and returns an ImageSource.
精彩评论