I have a Rectangle in WPF, I can set it\'s Fill by using
. This is my XAML for Rectangle:
&
You should use a Binding Converter, which may look like this:
public class ImageSourceConverter : IValueConverter
{
public object Convert(
object value, Type targetType, object parameter, CultureInfo culture)
{
return new BitmapImage(new Uri(
string.Format("pack://application:,,,/Images/{0}.jpg", value)));
}
public object ConvertBack(
object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
Declare the converter as XAML resource like this:
<Window.Resources>
<local:ImageSourceConverter x:Key="ImageSourceConverter" />
</Window.Resources>
und use it in your Binding:
<ImageBrush ImageSource="{Binding Path=itemNumber,
Converter={StaticResource ImageSourceConverter}}"/>
More about using converters can be found here: https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-convert-bound-data