15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1002 ❘ ChaPTer 35 cOre wpf<br />

for a column, you can set the Width property to * . To have the size doubled for another column, you specify<br />

2 * . The sample code, which defi nes two columns <strong>and</strong> three rows, doesn ’ t defi ne additional settings with the<br />

column <strong>and</strong> row defi nitions; the default is the star sizing.<br />

The grid contains several Label <strong>and</strong> TextBox controls. Because the parent of these controls is a grid, you<br />

can set the attached properties Column , ColumnSpan , Row , <strong>and</strong> RowSpan :<br />

< Window x:Class="LayoutDemo.GridWindow"<br />

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />

Title="GridWindow" Height="300" Width="300" ><br />

< Grid ShowGridLines="True" ><br />

< Grid.ColumnDefinitions ><br />

< ColumnDefinition / ><br />

< ColumnDefinition / ><br />

< /Grid.ColumnDefinitions ><br />

< Grid.RowDefinitions ><br />

< RowDefinition / ><br />

< RowDefinition / ><br />

< RowDefinition / ><br />

< /Grid.RowDefinitions ><br />

< Label Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0"<br />

VerticalAlignment="Center" HorizontalAlignment="Center" Content="Title" / ><br />

< Label Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"<br />

Content="Firstname:" Margin="10" / ><br />

< TextBox Grid.Column="1" Grid.Row="1" Width="100" Height="30" / ><br />

< Label Grid.Column="0" Grid.Row="2" VerticalAlignment="Center"<br />

Content="Lastname:" Margin="10" / ><br />

< TextBox Grid.Column="1" Grid.Row="2" Width="100" Height="30" / ><br />

< /Grid ><br />

< /Window ><br />

code snippet LayoutDemo/GridWindow.xaml<br />

The outcome arranging controls in a grid is shown in Figure 35 - 17. For easier viewing of the columns <strong>and</strong><br />

rows, the property ShowGridLines is set to true .<br />

figure 35-17<br />

For a grid where every cell has the same size, you can use the UniformGrid class.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!