Learning Silverlight 2 Series (11): Data binding

Source: Internet
Author: User
Tags silverlight

This is the 11th article in the series, which describes data binding in Silverlight 2.

Data binding Mode

In Silverlight 2, data binding is supported in three modes.

1.OneTime: Bind once, use source data to update the target when binding is created, apply to display only data without updating data.

2.OneWay: One-way binding, updated to target when binding is created or when the source data changes, and applies to data that displays changes.

3.TwoWay: Bi-directional binding, you can update both the source data and the target at any time.

Jesse Liberty The example of a very image, using Silverlight to develop an online bookstore, showing the book title, author and other information, using the onetime mode, these data generally will not be changed; display price information using OneWay mode, Because the administrator may adjust the price in a single day; the number of books is displayed in TwoWay mode, with the quantity changing as the user's subscription changes, i.e. both the target and the source data are updated.

Simple Data binding

In this example we will do a simple data binding to display the user information, which is the following XAML:

<grid x:name= "LayoutRoot" background= "#46461F" >
<Grid.RowDefinitions>
<rowdefinition height= "160" ></RowDefinition>
<rowdefinition height= "></RowDefinition>"
<rowdefinition height= "></RowDefinition>"
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<columndefinition width= "></ColumnDefinition>"
<columndefinition width= "*" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<image source= "terrylee.jpg" width= "height=" "100"
Horizontalalignment= "left" grid.row= "0" grid.column= "1"/>
<textblock foreground= "White" fontsize= "text=" Name: "
grid.row= "1" grid.column= "0" horizontalalignment= "right"/>
<textblock x:name= "Lblname" foreground= "White" fontsize= "18"
grid.row= "1" grid.column= "1" horizontalalignment= "left"/>
<textblock foreground= "White" fontsize= "text=" Location: "
grid.row= "2" grid.column= "0" horizontalalignment= "right"/>
<textblock x:name= "lbladdress" foreground= "White" fontsize= "18"
grid.row= "2" grid.column= "1" horizontalalignment= "left"/>
</Grid>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.