private void HeroMouseEnter(object sender, MouseEventArgs e)
{
((Image)sender).Source = GetGlowingImage(((Image)sender).Name);
}
pub
Going by your edit, you are happy to have a static set of images in resources. If that's correct, you can do this:
then load it as:
public ImageSource GetGlowingImage(string name)
{
switch (name)
{
case "Andromeda":
return (ImageSource)FindResource("andromeda64");
default:
return null;
}
}
FindResource requires you to be in code-behind for something in the visual tree (e.g. an event handler). If this isn't the case, or if you want to be able to load things that aren't in a resource dictionary, see Cory's answer. The advantage of using and reusing resources is that you don't need to create a BitmapImage each time you use it (though in this case the overhead cost of doing so will be insignificant).