Reputation: 17233
im currently accessing my image in XAML and setting it to a picturebox with
Source="/SocialShock-WPF-Client;component/Images/blue-bar-replication.png"
how would i do this in the codebehind?
Upvotes: 0
Views: 671
Reputation: 15823
Exactly the same way. Create BitmapImage object (pass Uri object with the same path to its constructor). Then set Image's Source property to the newly created BitmapImage object.
Upvotes: 0
Reputation: 1380
public static BitmapImage GetImageFromResource(string name)
{
var res = new BitmapImage();
res.BeginInit();
res.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SocialShock-WPF-Client.Images." + name);
res.EndInit();
return res;
}
Invoke this method with the image name, "blue-bar-replication.png" in your case. The image build action should be set to EmbededResource.
Upvotes: 1