Load External Image into WPF using OpenFileDialog
A simple WPF control implementation to browse and load an image into the app
This is my first time I made a tutorial about WPF. I don’t think it’s a new technique, but I just want to share what I learned at home. I assume that you understand WPF a little bit. In this tutorial I’d like to show you how to load external image into WPF using
Create a new WPF Project, File → New → Project… and chose WPF Application (by the way, I’m using Visual Studio 2008 in this tutorial). You’ll see an empty window called
Modify your window just like the picture below:
Just kidding, you don’t have to design it yourself, just copy the XAML code below and paste it inside your
Now, let’s get into the logic. Double click on
btnLoad and you’ll see
private void btnLoad_Click(object sender, RoutedEventArgs e). Add the code below inside that function.
Now, let’s test the project, run the project (press F5 button), click Load button and chose a picture you like. And you’ll see the picture inside your WPF window.
Hope this simple tutorial helps you. See you on my next tutorial.
Cover Photo by Farzad Nazifi on Unsplash.