Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

StackPanel

StackPanel is a very simple panel that arranges its children in a row or a column. You will not normally use StackPanel to lay out your whole user interface. It is most useful for arranging small subsections. Example 3-1 shows how to build a simple search user interface.

Example 3-1. StackPanel search layout

<StackPanel Background="#ECE9D8">
  <TextBlock Margin="3">Look for:</TextBlock>
  <ComboBox  Margin="3"/>
  <TextBlock Margin="3">Filtered by:</TextBlock>
  <ComboBox  Margin="3"/>
  <Button    Margin="3,5">Search</Button>
  <CheckBox  Margin="3">Search in titles only</CheckBox>
  <CheckBox  Margin="3">Match related words</CheckBox>
  <CheckBox  Margin="3">Search in previous results</CheckBox>
  <CheckBox  Margin="3">Highlight search hits (in topics)</CheckBox>
</StackPanel>

Figure 3-1 shows the results. As you can see, the UI elements have simply been stacked vertically one after another. This example used the Margin property to space the elements out a little. Most elements use a single number, indicating a uniform margin all around. The Button uses a pair of numbers to specify different vertical and horizontal margins. This is one of several standard layout properties available on all WPF elements, which are all described in the "Common Layout Properties" section, later in this chapter.

Tip

Many of the examples in this book represent typical snippets of XAML, rather than complete self-contained programs. You can download runnable versions of the examples from the book's web site at http://sellsbrothers.com/writing/wpfbook ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page