I want to show Image in my WPF Window. I have put this code to do so.
<Image x:Name="ImageControl" Stretch="Fill" Margin="2" Source="{Binding imgSource}"/>
and in code behind I have put,
public ImageSource imgSource
{
get
{
logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri(@"C:\MyFolder\Icon.jpg");
logo.EndInit();
return logo;
}
}
This code shows image fine but I also should be able to change image runtime, That is, I want to replace Icon.jpg with another Image.
MyFolder is the folder path that will contain an Image "Icon.jpg" (Name would always be same).
So whenever I try to replace Icon.jpg with anyother Image, I get an error That Image file in Use
Can Anyone suggest how to overcome this issue. Please let me know if I need to clear my question.
Thanks in Anticipation.