Book Image

Mastering LOB Development for Silverlight 5: A Case Study in Action

Book Image

Mastering LOB Development for Silverlight 5: A Case Study in Action

Overview of this book

Microsoft Silverlight is fully established as a powerful tool for creating and delivering Rich Internet Applications and media experiences on the Web. This book will help you dive straight into utilizing Silverlight 5, which now more than ever is a top choice in the Enterprise for building Business Applications. "Mastering LOB Development for Silverlight 5: A Case Study in Action" focuses on the development of a complete Silverlight 5 LOB application, helping you to take advantage of the powerful features available along with expert advice. Fully focused on LOB development, this expert guide takes you from the beginning of designing and implementing a Silverlight 5 LOB application, all the way through to completion. Accompanied by a gradually built upon case study, you will learn about data access via RIA and Web services, architecture with MEF and MVVM applied to LOB development, testing and error control, and much more.With "Mastering LOB Development for Silverlight 5: A Case Study in Action" in hand, you will be fully equipped to expertly develop your own Silverlight Line of Business application, without dwelling on the basics of Enterprise Silverlight development.
Table of Contents (19 chapters)
Mastering LOB Development for Silverlight 5: A Case Study in Action
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
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'.