Open the Toolbox window if it is not already open and expand the Silverlight XAML Controls tab.
.png)
From the Toolbox, drag a TextBlock control to just after the </Grid.ColumnDefinitions> end tag in XAML view.
<TextBlock></TextBlock> markup is added to XAML view.
In the TextBlock start tag, add the following Text property.
<TextBlock Text="Name:"></TextBlock>
After the Name TextBlock, add another TextBlock with Text="Date:".
After the Date TextBlock, add another TextBlock with Text="Message:".
In the Preview window, you can see that the TextBlock elements overlap each other in the first cell. To position the TextBlock elements in Grid cells, you have to specify the Grid..::.Row and Grid..::.Column properties.
In the start tag for the Name TextBlock, add the following properties.
Grid.Row="0" Grid.Column="0"
Notice that the properties are named Grid..::.Row and Grid..::.Column instead of just Row and Column. Grid has Row and Column properties, but TextBlock does not. However, you can "attach" the Row and Column properties from Grid to the TextBlock. Grid..::.Row and Grid..::.Column are special properties called attached properties. Attached properties is a concept that you will use in XAML. For more information, see Attached Properties Overview.
In the start tag for the Date TextBlock, add the following properties.
Grid.Row="1" Grid.Column="0"
In the start tag for the Message TextBlock, add the following properties.
Grid.Row="2" Grid.Column="0"
In the Preview window, the TextBlock elements are now positioned in the appropriate cells.
Add the following ColumnSpan attached property to the Message TextBlock to allow the text to span across both columns.
From the Toolbox, drag a TextBox control to just after the Message TextBlock.
In the start tag, set the following properties.
<TextBox Text="Your Name" Grid.Row="0" Grid.Column="1"></TextBox>
Notice that the TextBox fills up the entire Grid cell. It fills the cell because the HorizontalAlignment and the VerticalAlignment properties are set to Stretch by default.
In the start tag for the TextBox, set the Width property to 150.
Notice that the TextBox is centered in the Grid cell.
In the start tag for the TextBox, set the alignment to left, by adding the following HorizontalAlignment property.
HorizontalAlignment="Left"
Below the Your Name TextBox, drag a StackPanel control from the Toolbox.
A StackPanel is a useful control to stack elements vertically or horizontally. In the Grid cell below the Your Name TextBox, you will stack two controls vertically.
In the start tag for the StackPanel, add the following properties.
Grid.Column="1" Grid.Row="1" Orientation="Vertical"
From the Toolbox, drag a Calendar control to within the StackPanel element.
When you add the Calendar control, you will notice that the tag name is slightly different than the other controls. It is prefixed with "basics:" (or another prefix). The Calendar control is not part of the core Silverlight controls and is implemented in a different assembly. The Calendar control is part of the Silverlight SDK. To use the Silverlight SDK controls, you must add an XML namespace and a reference to the assembly. When you drag a Silverlight SDK control to XAML view, an XML namespace and a reference are added automatically at the top of the Page.xaml file in the <UserControl> tag. As can be see in the following markup, the basics namespace uses the System.Windows.Controls.dll assembly.
<UserControl xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
For more information about the Silverlight SDK and the controls in the Silverlight SDK, see Silverlight Tools and Controls by Function.
In the start tag for the Calendar, set the following properties.
Setting the SelectionMode to SingleDate specifies to allow only a single date to be selected.
SelectionMode="SingleDate" HorizontalAlignment="Left"
From the Toolbox, drag a Button control to just after the Calendar control, but within the StackPanel element.
Since the Orientation property of the StackPanel is set to Vertical, the Button appears after the Calendar.
In the start tag for the Button, set the Width, Height, HorizontalAlignment, and Content properties.
<Button Width="75" Height="25" HorizontalAlignment="Left" Content="OK"></Button>
A Button control does not have a Text property, but it does have a Content property. A Button has a Content property because you can actually add other elements, such as images or other controls, as the content for a Button.
On the File menu, click Save All.
At this point, all of the controls have been added. Your XAML should be similar to the following.
<UserControl xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="HelloSilverlight.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Beige" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="220"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75" />
<ColumnDefinition Width="325"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Name:" Grid.Row="0" Grid.Column="0"></TextBlock>
<TextBlock Text="Date:" Grid.Row="1" Grid.Column="0"></TextBlock>
<TextBlock Text="Message:" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"></TextBlock>
<TextBox Text="Your Name" Grid.Row="0" Grid.Column="1" Width="150" HorizontalAlignment="Left"></TextBox>
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical">
<basics:Calendar SelectionMode="SingleDate" HorizontalAlignment="Left"></basics:Calendar>
<Button Width="75" Height="25" HorizontalAlignment="Left" Content="OK"></Button>
</StackPanel>
</Grid>
</UserControl>
Press F5 or click Start Debugging to run the application.
The following illustration shows an example of the browser window. You can type text in the TextBox, you can select dates in the Calendar, but the Button does not do anything because code has not been added yet.
.png)