If your h == null
when there is no image returned then there is easier way to do what you want - use TargetNullValue
in Binding:
<Image Source="{Binding url, TargetNullValue='/Example;component/Resources/placeholder.png'}" Width="100" Height="100"/>
In above case be sure to set BuildAction of placeholder.png
as Resource
. (Example
here is your project name, Resources
is a path to the file). You can also bind directly to your h
in this case.
If you insist on using designed property then:
I'm not sure how the rest of your code looks like, but but when you have defined binding like this:
<Image Source="{Binding url}" Width="100" Height="100"/>
When the item is being loaded the Getter
of url
is fired. So using Setter
to repleace null
with Bitmapimage
won't help here (of course if you are not running Setter
somewhere else, but defining Setter
without value
- kind a weird, implement it different or provide separate method.
Check if that would help:
public BitmapImage url
{
get
{
if (h == null)
return new BitmapImage() { UriSource = new Uri("/Projectname;component/path/profile-placeholder.gif", UriKind.Relative) };
return h;
}
}
Setting UriSource
depends also how your file is defined in your project (Build Action), you can take a look here.