views:

49

answers:

1

Hi All At Silverlight 4.0 XAML page (not using code behind), I'm binding Source to Image control. I want to show default image when retrival ImageUrl (from Database) is null or empty.

I'm trying the TargetNullValue as following , but not showing default image when ImageUrl is null or empty

     <Image Grid.Column="0"
               x:Name="YourAvator"
               Width="100"
               Height="100"
               Source="{Binding Path=ImageUrl, Mode=OneWay, TargetNullValue='../Images/default_avator.jpg'}"
               Stretch="Fill" />

Please advise me.

Thanks.

A: 

I would do it simply by using a converter:

Source="{Binding Path=ImageUrl, Mode=OneWay, Converter={StaticResource MyImageConverter}, ConverterParameter=../Images/default_avator.jpg}"

In MyImageConverter you look at 'value', if it's null you return a new ImageSource with the URL received as ConverterParameter.

Francesco De Vittori
Thanks I'll try.
SOFextreme