Thursday, March 8, 2012

Silverlight 5/Visual Basic: Add event handling code

- Modify from the last article "Hello Visual Basic Silverlight 5, using Microsoft Visual Studio 11 Ultimate Beta". Edit MainPage.xaml in XAML view to add property of Click="button1_Click", to specify the call-back function once the button clicked.
    <Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock x:Name="textBlock" Text="Hello!"></TextBlock>
<Button x:Name="button1" Click="button1_Click" Content="Click Me"></Button>
</StackPanel>
</Grid>


- Click the Design tab to switch to Design view, and double click on the button, to insert code of button1_Click() in MainPage.xaml.vb.


- Enter the code:
    Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
textBlock.Text = "Hello, I'm here!"
End Sub

button1_Click()

- Run it.
Silver 5/Visual Basic: Add event handling code


Next:
- Border of Silverlight

No comments:

Post a Comment