I am trying to create a GridView of dynamically-created Grid items, each of which have their background set as follows:
<Grid.Background>
<ImageBrush ImageSource="{Binding FilePath}" Stretch="UniformToFill" />
</Grid.Background>
If FilePath is the absolute path to the file that should be loaded for each Grid item, is there a way that I can convert this value to an ImagePath so that the image will load?
I am getting the FilePath using a file picker. The value is then being saved to an ObservableCollection that is loaded when the app starts and displayed by being set as the DataContext.
There is no ImagePath
property that I know of and ImageSource
is not a path or even a Uri
. You should probably bind your ImageSource
to a BitmapImage
. Simply create a new BitmapImage
and call SetSource
or SetSourceAsync
if you want to wait for it to load before updating your image - e.g. to show a placeholder image, a progress indicator or fade in the image.