In general, there is a certain image (file), but Image does not want to display it. Here is the code with which I am trying to display an image:

BitmapImage bitmp = new BitmapImage(); bitmp.BeginInit(); bitmp.UriSource = new Uri(file, UriKind.Relative); bitmp.CacheOption = BitmapCacheOption.OnLoad; bitmp.EndInit(); return bitmp; 

ImageSource is returned. What could be wrong here? The returned image is placed in the Image.Source. I tried to set the relative and absolute Uri, but this did not change the situation.

  • And what is written interesting in the Output window? - VladD
  • And yes, what do you have in the file ? - VladD
  • In file, there is a relative path to the picture (in my case, imgres\somefile.png , and in output, the System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Threading.Tasks.Task 1[System.Windows.Media.ImageSource]' and 'System.Windows.Media.ImageSource'. Consider using Converter property of Binding. BindingExpression:Path=PlayerIcon; DataItem='<>f__AnonymousType6 8' (HashCode=144639410); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') - Rupppppppet

1 answer 1

Thanks VladD for the hint, the problem was that I forgot to add. Result to the function, it turned out GetImage("path").Result , since function - asynchronous

  • If you have an asynchronous function, it is better to use not a blocking Result, but await. But wait, what is your asynchronous function? - VladD
  • The one that returns the image - Rupppppppet
  • one
    But in the code you gave, everything is in sync. Maybe this function is synchronous all? - VladD