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 OpenFileDialog.
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 Window1.xaml.
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 Window1.xaml
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.