It can be helpful to start from the beginning when working with new technologies. This post explains how to create a minimal WPF application that produces a single window with a gradient in it, as shown in Figure 1. The point of this exercise is to build the app from scratch, choosing File | New Project | Empty Project rather than File | New Project | WPF Application. The benefit of this exercise is to simply see what ingredients go into the production of a minimal WPF program.
Figure 1: A Simple WPF window with a gradient.
Figure 2: The References section from the SimpleWpf project.
The complete source code to this project is shown in Listing 1. You can see that an Application object is created in the Main method, and that a few minimal fields of the window are filled out in the constructor. I also create a WPF LinearGradientBrush and set it as the Background for the window.
class Program: Window
static void Main(string args)
Application application = new Application();
Width = 320;
Height = 260;
Title = "A Colorful Window";
Background = new LinearGradientBrush(Colors.AliceBlue, Colors.Aquamarine,
new Point(0, 0), new Point(1, 1));
I should perhaps end by reminding you that the simplest way to create a WPF application in Visual Studio is to choose File | New Project | WPF Application. I have shown you this alternative technique simply because I hope you find it interesting or entertaining. It also illustrates that it is possible, though not necessarily recommended, to build WPF applications without using XAML.
The complete Source is on my LINQ Farm. Here is direct link to the download.