Simple Example of Silverlight data binding (markup extension)

Source: Internet
Author: User

In this example, the bound data is an instance of the owner class. Now, an owner class is added to the Silverlight project.

Class owner

Public class owner
{
Public int ownerid {Get; set ;}
Public String firstname {Get; set ;}
Public String lastname {Get; set ;}
Public String address {Get; set ;}
Public String zipcode {Get; set ;}
Public String city {Get; set ;}
Public String state {Get; set ;}
Public String country {Get; set ;}
Public datetime birthdate {Get; set ;}
Public datetime customersince {Get; set ;}
Public String imagename {Get; set ;}
Public datetime lastactivitydate {Get; set ;}
Public double currentbalance {Get; set ;}
Public double lastactivityamount {Get; set ;}
}

 

 

Create an instance of the owner class in mainpage. XAML. CS.

 Mainpage. XAML. CS

Public Mainpage ()
{
Initializecomponent ();
Initializeowner ();
}

Private   Void Initializeowner ()
{
Owner =   New Owner ();
Owner. ownerid =   1234567 ;
Owner. firstname =   " Zhu " ;
Owner. lastname =   " JZ " ;
Owner. Address =   " Chaoyang BJ " ;
Owner. zipcode =   " 100001 " ;
Owner. City =   " Beijing " ;
Owner. Country =   " China " ;
Owner. State =   " Beijing " ;
Owner. imagename =   " Wo.jpg " ;
Owner. lastactivityamount =   100 ;
Owner. lastactivitydate = Datetime. today;
Owner. currentbalance =   1234.56 ;
Owner. Birthdate =   New Datetime ( 1986 , 6 , 8 );
Owner. customersince =   New Datetime ( 2009 , 12 , 20 );
}

 

 

 

By now, you have used the extended identity syntax (Markup Extension) Implements the text attribute bound to textblock. In the last step, bind the owner class instance to the control.CodeTo achieve:

PublicMainpage ()

{
Initializecomponent ();
Initializeowner ();
Ownerdetailsgrid. datacontext = Owner;
}

 

 

 The effect is as follows:

 

 

 

Let's look back at The XAML code. As mentioned above, textblock data binding is implemented through extended identifiers:

 <TextblockText="{Binding customersince}" />

 

In fact, this is an abbreviation. The complete binding syntax is as follows:

 <TargetcontrolTargetproperty="{Binding sourceproperty, somebindingproperties}" />

 

 

 

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.