Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering LOB Development for Silverlight 5: A Case Study in Action

You're reading from   Mastering LOB Development for Silverlight 5: A Case Study in Action Develop a full LOB Silverlight 5 application from scratch with the help of expert advice and an accompanying case study with this book and ebook

Arrow left icon
Product type Paperback
Published in Feb 2012
Publisher Packt
ISBN-13 9781849683548
Length 430 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (19) Chapters Close

Mastering LOB Development for Silverlight 5: A Case Study in Action
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Express Introduction to Silverlight FREE CHAPTER 2. Forms and Browsing 3. Data Binding 4. Architecture 5. RIA Services Data Access 6. Out of Browser (OOB) Applications 7. Testing your LOB Application 8. Error Control 9. Integration with other Web Applications 10. Consuming Web Services 11. Security Index

Interacting with Code-Behind


In the following example, we will allow the user to change the message Hello World! to one of their choice. Starting from the previous example, we will follow the given steps:

  1. Open the mainpage.xaml file.

  2. Replace the XAML code inserted in the previous example by the one highlighted as follows (we have added an additional textbox, a button, and identifiers for the controls).

    <Grid x:Name="LayoutRoot" Background="White">
      <StackPanel Orientation="Vertical">
      <TextBlock x:Name="tbLabel" 
      Text="Hello World!" 
      FontSize="20"/>
                <StackPanel Orientation="Horizontal">
                    <TextBlock 
                        Text="New Text:" 
                        FontSize="16"/>
                    <TextBox 
                        x:Name="txInput" 
                        Width="120"/>
                    <Button Content="Change"/>
                </StackPanel>
            </StackPanel>
        </Grid>
  3. When we build and execute the project, we realize that our window now has the aspect as shown in the following screenshot:

  4. Next, we must implement the response to the Click event of the Change button.

  5. Hook to the Click event directly in the XAML file. As soon as we start typing, IntelliSense (Microsoft's implementation of autocompletion) will ask us if we want to create the method (hitting Enter or Tab would create the method with the default name or with the name of the control after selecting a Click event).

  6. Execute the same operation from the Properties panel (or by directly double-clicking on the button control):

  7. As a result, XAML will look as follows:

    <Button Content="Change" Click="Button_Click"/>
  8. In Code-Behind, in the method invoked by the Click event, we must add a line of code, which transfers the text content entered by the user to the tag where we showed 'Hello World'.

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      tbLabel.Text = txInput.Text;
    }
  9. When we execute, we will be able to enter a new text that substitutes 'Hello World'.

You have been reading a chapter from
Mastering LOB Development for Silverlight 5: A Case Study in Action
Published in: Feb 2012
Publisher: Packt
ISBN-13: 9781849683548
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime