My code:
<Image Height="100" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top">
<Image.Source>
<BitmapImage DecodePixelWidth="100">
<BitmapImage.UriSource>
<PriorityBinding>
<Binding Path="MyModel1.ImagePath"/>
<Binding Path="MyModel2.ImagePath"/>
</PriorityBinding>
</BitmapImage.UriSource>
</BitmapImage>
</Image.Source>
</Image>
In my viewmodel, the value of ImagePath:
public object ImagePath
{
get { return new Uri("F:/myFolder/default.png", UriKind.Absolute); }
}
The path F:/myFolder/default.png exists. I get the error: Property 'UriSource' or property 'StreamSource' must be set. Why is this happening? Where am I making a mistake?
Just use the plain
string
file paths and let the Framework convert them toBitmapImage
elements:...