I'm trying to set FallbackValue in case when my converter cannot be call, but I'm not sure how to do that.
<Image Source="{Binding FallbackValue="Pictures/Unknown.png", Path=LatestPosition.DeviceFamily, Converter={x:Static conv:ConverterSet.DeviceTypeToImageSourceconverter}}" Name="image1" Stretch="Fill" Margin="5,8" Width="150" Height="150" Grid.RowSpan="4" />
Paths of external images in converter looks like that and when LatestPosition!=null the image is set in proper way.
private static readonly ImageSource Dev1 = new BitmapImage(new Uri("/Pictures/dev1.png", UriKind.Relative));
private static readonly ImageSource Dev2 = new BitmapImage(new Uri("/Pictures/dev2.png", UriKind.Relative));
For the Image control, when you Binding the Source property with a URI string, it will automatically convert the URI to a BitmapImage. But if you set the FallbackValue and TargetNullValue as URI string, it will not display.
You need to set it as BitmapImage:
<Window.Resources>
<BitmapImage x:Key="DefaultImage" UriSource="/Resources;component/Images/Default.jpg" />
</Window.Resources>
<Image Width="128"
Height="128"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="{Binding Photo,FallbackValue={StaticResource DefaultImage},
TargetNullValue={StaticResource DefaultImage}}" />
As we set the FallbackValue and the TargetNullValue as StaticResource of BitmapImage, It works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With