Here is binding:
<Image Width="16" Height="16" Source="{Binding SwitchForImage, Converter={StaticResource stringToImage}}" HorizontalAlignment="Left">
</Image>
and here is the Convertor
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string type = (string)value;
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri(@"pack://application:,,,/Resources/"+type+@"Icon.png");
logo.EndInit();
return logo;
}
when i run ,gives this exception "Cannot locate resource 'resources/*icon.png' ".But i put png files into folder named Resources.I am creating library.These all in library.For test i used it,and then occured this problem.
I added png files as"include to project".Build action is "Content".But i tried others also(Resource,Embedded resource)
[Answer] I changed Build Action to Resource and changed Convert like that:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return "/AutoComplete;component/Resources/" + (string)value + "Icon.png";
}
And everything work normally.
I changed Build Action to Resource and changed Convert method like that:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return "/AutoComplete;component/Resources/" + (string)value + "Icon.png";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.