|
|
Title | Use XAML to make a button that contains a grid holding three labels in VB 2005 and .NET Framework 3.0 |
Description | This example shows how to use XAML to make a button that contains a grid holding three labels in VB 2005 and .NET Framework 3.0. |
Keywords | XAML, VB 2005, Visual Basic 2005, .NET Framework 3.0, gradient, grid, Label, Button |
Categories | VB.NET, WPF |
|
|
One interesting feature of the .NET Framework 3.0 controls is that their Content property, which determines what they display, can contain practically anything. This example shows a Button that contains a Grid that holds three Labels. You cannot build this by using the graphical XAML designer but you can do it easily in XAML code.
The Window's main Grid element contains a Button element. That element contains a Grid. The Grid's RowDefinitions define three rows that use up 33, 33, and 34 percent of the Grid's height. Similarly its ColumnDefinitions define columns that use up 33, 33, and 34 percent of the Grid's width.
The Grid also contains three Label controls. The Grid.Row and Grid.Column attributes of the Label XAML elements determine the Grid rows and columns that contain the controls. The second Label also has a Grid.ColumnSpan attribute that indicates that it spane three columns. The second and third Labels use VerticalAlignment and HorizontalAlignment attributes to specify thir alignment within their Grid cells.
|
|
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="XamlGridButton" Height="193" Width="219"
>
<Grid>
<Button Name="btnGrid" Height="100" Width="150">
<Grid Height="90" Width="140">
<Grid.RowDefinitions>
<RowDefinition Height="33*" />
<RowDefinition Height="33*" />
<RowDefinition Height="34*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="34*" />
</Grid.ColumnDefinitions>
<Label Content="UL" Grid.Row="0" Grid.Column="0" />
<Label Content="In The Middle" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Label Content="LR" Grid.Row="2" Grid.Column="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
</Grid>
</Button>
</Grid>
</Window>
|
|
Note that this example uses the .NET Framework 3.0 and XAML. To use them, you need to install the Windows SDK (currently called the Windows Vista SDK) available for download on Microsoft's Web site.
|
|
|
|
|
|