O'Reilly logo

Learning C# 3.0 by Brian MacDonald, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WPF Differences from Windows Forms

What you did in Hello WPF isn't much different from what you could have done in Windows Forms. There are a few differences, however, even in this simple application, which aren't readily apparent. For example, run the program again, and try stretching out the borders of the window, as shown in Figure 19-4.

Notice how the "Say Hello" button stretches as you stretch the window. That wouldn't happen in Windows Forms without some extra tweaking on your part (you can load one of the examples from Chapter 18 if you want to check that). In fact, the label stretches too, but you can't see that because the Label control has no border, and it's the same color as the background.

When you stretch the window in WPF, the controls stretch with it.

Figure 19-4. When you stretch the window in WPF, the controls stretch with it.

Tip

If the button doesn't stretch for you, you probably have the button placed too far to one side of the window, so the margin is set to zero. Go back to the Design view and move the button until you see the arrows connecting the left and right sides of the button to the sides of the window.

Close the application and go back to the Window1.xaml window to see how that happened. Expand the XAML part of the window so that you can see it better. You'll find that it looks something like Example 19-1, although the actual values will probably be different in your case.

Example 19-1. The XAML for your Hello WPF application ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required