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}" />