15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

layout ❘ 999<br />

<br />

Label with a border<br />

<br />

code snippet DecorationsDemo/MainWindow.xaml<br />

The Viewbox stretches <strong>and</strong> scales its child to the available space. The StretchDirection <strong>and</strong> Stretch<br />

properties are specific to the functionality of the Viewbox. These properties allow setting if the child is<br />

stretched in both directions, <strong>and</strong> if the aspect ratio is preserved:<br />

<br />

Label with a viewbox<br />

<br />

The BulletDecorator class decorates its child with a bullet. The child can be any element (in this example,<br />

a ComboBox). Similarly, the bullet can also be any element. The example uses an Image, but you can use<br />

any UIElement:<br />

<br />

<br />

<br />

<br />

<br />

<br />

Granny Smith<br />

Gravenstein<br />

Golden Delicious<br />

Braeburn<br />

<br />

<br />

<br />

tayouT<br />

To define the layout of the application, you can use a class that derives from the Panel base class. Several<br />

layout containers are available that are discussed here. A layout container needs to do two main tasks:<br />

measure <strong>and</strong> arrange. With measuring, the container asks its children for the preferred sizes. Because the<br />

complete size answered by the controls might not be available, the container next decides <strong>and</strong> arranges<br />

the size <strong>and</strong> positions of its children.<br />

stackPanel<br />

The Window can contain just a single element as content. If you want to have more than one element inside there,<br />

then you can use a StackPanel as a child of the Window, <strong>and</strong> add elements to the content of the StackPanel.<br />

The StackPanel is a simple container control that just shows one element after the other. The orientation of the<br />

StackPanel can be horizontal or vertical. The class ToolBarPanel is derived from StackPanel:<br />

<br />

<br />

Label<br />

TextBox<br />

CheckBox<br />

CheckBox<br />

<br />

ListBoxItem One<br />

ListBoxItem Two<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!