I have a little problem. I would like to add an image from a folder to a project so that I don't have a mess in the project. The images that I have directly in the project not in the folder . Do you know what to do? I want to change the images after clicking the button, that's why I want more images there
My code where I want change Images, it works with Images inside project
public void ChangeImg(Uri resourceUri,Image image)
{
StreamResourceInfo streamInfo =
Application.GetResourceStream(resourceUri);
BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
var brush = new ImageBrush();
brush.ImageSource = temp;
image.Source = brush.ImageSource;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ChangeImg(new Uri("images/timetable_Unselected.png",
UriKind.Relative), img_Home_Unselected);
}
CodePudding user response:
Problem solved! Click on the file -> Add -> Exististing File -> SELECT ALL FILES
CodePudding user response:
did you add that image by drag and drop the file? it has not become a file the problem is that it has not been loaded in the most appropriate way.
Try to add the file as a resource, to do that go to the project menu in the resource tab. In that section add resource specifying the type and you should be good to go. Later when you want to call the image from code you can find it in the resources that are easily accessible via code.
to call image via code search on stack is well documented.