I have a converter which implements the IValueConverter interface. Here's the Convert method:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return String.Concat(@"..\Images\myFolder\", System.Convert.ToString(value), ".png");
}
Here it is in my xaml code, in the resources:
<converters:ImageSourceConverter x:Key="ImageSourceConverter"/>
And here's how I use it:
<Image Source="{Binding Path=myCategoryId, Converter={StaticResource ImageSourceConverter}}" Width="150" Height="150"></Image>
The problem I have is this: I have a few folders with images in my solution. The path for the images is this one:
..\Images\myFolder\1.png
..\Images\myFolderJohn\2.png
..\Images\myFolderJack\3.png
where the name of the file is an id. The code I have in the Convert method works only for the images in myFolder. The name of the folder depends on the user control in which the image is placed. So, it should be something like this:
if (userControl == "John")
return String.Concat(@"..\Images\myFolderJohn\", System.Convert.ToString(value), ".png");
if (userControl == "Jack")
return String.Concat(@"..\Images\myFolderJack\", System.Convert.ToString(value), ".png");
How do I know the user control from which the image is shown, in the Convert method?