WPF?!

When you the hear the acronym WPF you are more likely to start thinking about a very similar combination of letters WTF. So what on Earth is WPF, you may ask? Well, WPF stands for Windows Presentation Foundation, which is Microsoft’s GUI framework, used with the .NET framework.

But what then is a GUI framework? Well, GUI stands for Graphical User Interface, and is a graphical (rather than purely textual) user interface to a computer. As you read this, you are probably looking at the GUI of your particular Web browser on your laptop or mobile device.

So how do you create a WPF project? Well, when you first launch Visual Studio you are given various options for project types, of which WPF Application is one.

There are two distinct sections of a WPF project; the XAML Designer and the XAML Code Behind file.

The XAML Designer lets you create a visual interface for your project. This is achieved by simply dragging and dropping controls from the Toolbox onto the Main window.

You can edit XAML directly in XAML view. Alternatively, my preferred preference is to make adjustment to object names, fonts choices, and button colors within the Design XAML tab and the properties panel itself. Don’t forget that the properties panel will reflect the available properties for the object you have selected in the Main Window. So if you aren’t seeing the selections you thought you should you are probably selected in the wrong object.

XAML Designer

With my graphic design background, I instantly gravitated to the XAML designer as an opportunity to be creative because of its flexibility and customization options. In a recent WPF project, I built a functioning calculator with a wood design. In XAML Designer you can add unique images for your background as well as to the face of buttons. This gives designers huge creative control to import images they have designed in Photoshop. When applying an image to a button you just need to make sure you specify the file path and extension of your image file in the image source.

C# adding a click event to a button

So that’s all well and good having a beautiful interface, but how do I make my buttons actually do something or trigger something?? Well it really is as easy as double clicking on the button itself. When you do this is switches you over to the XAML.cs window, and populates the C# method for your click event. You can then write the applicable C# code that you wish to run upon the button being pressed, as well as much much more.

Overall, I really like WPF because it is extremely powerful and flexible for both the designer and the programmer in unison.

Calculator built in WPF
Show your support

Clapping shows how much you appreciated Nikole McStanley’s story.