Beginning Silverlight 2.0 Development using Visual Studio 2008 - Coding your first Silverlight 2 application
(Page 3 of 6 )
This continues the previous section. In the previous section, we created a new Silverlight application. In this section, we will develop some code and execute the application.
The first step is to create the XAML markup, which simply contains a button and a textbox. Open Page.xaml (available in FirstSilverlightApp) and modify the existing markup so that it looks like the following:
<UserControl x:Class="TestSilverlight.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas Margin="30,26,31,34">
<Button Height="31" Width="113" Canvas.Left="102" Canvas.Top="21" Content="Disp Message" x:Name="btnShow" Click="btnShow_Click"/>
<TextBox Height="25" Width="168" Canvas.Left="71" Canvas.Top="82" Text="" TextWrapping="Wrap" Background="#FFFFFFFF" x:Name="txtFirst"/>
</Canvas>
</UserControl>
Open the code behind (Page.xaml.vb) and modify it so that it matches the following:
Partial Public Class Page
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Me.txtFirst.Text = "Hello world"
End Sub
End Class
After completing all of the above steps, execute the application and test the button. It should look like the following (Fig 06):

You can also modify the properties of a control dynamically. This is explained in the next section.
Next: Explaining the code >>
More BrainDump Articles
More By Jagadish Chaterjee