I got a class that I'm hooking later as an ItemsSource on a Listbox. This Listbox got an Item which got an Image Binding "{Binding LocalImage}". The issue is that when the Item is getting the value from LocalImage, is returning a null value when it shouldn't. The void doesImageExistLocally works perfectly and has been tested on another project.
Calling it alone from the Main void does correctly output the path of the image, so its not an issue on the void, is an issue with the class / listbox item getting the value. Also need to note that the string Image is assigned correctly too. Console.WriteLine(Logic.doesImageExistLocally("imageurl"));
public class Test {
private string _LocalImage;
public string Image {get; set:}
public string LocalImage
{
get { return _LocalImage; }
set { _LocalImage = doesImageExistLocally(Image); }
}
}
Edit:
Test test = new Test();
test.Image = "URL";
doesImageExistLocally(Image); // output = Images/name-of-picture.jpg
Console.WriteLine(test.LocalImage); // output = null;
Void code:
public static string doesImageExistLocally(string imageURL)
{
Uri uri = new Uri(imageURL);
string path = "Images/" + System.IO.Path.GetFileName(uri.LocalPath);
Console.WriteLine(path);
if (!File.Exists(path))
{
using (WebClient client = new WebClient())
{
client.DownloadFile(new Uri(imageURL), path);
}
}
return path;
}