Stable transformation of SL review notes-basics (V. Data Binding)

Source: Internet
Author: User

For more information about object binding, see the following.

1. Bind the object property to the property of the SL control. The object can be placed in the collection.

You can bind an "object" to the "datacontext" attribute of the UI element, for example, textbox. Then, set "{binding notepad, mode = twoway}" in the "text" attribute of the textbox }"

2. Three data binding modes: onetime (only one change), oneway (one-way change), and twoway (two-way change ).

I will not explain it much.Code.

public class notepaditem: inotifypropertychanged
{< br> Public String _ title;
Public String title
{< br> get {return _ title ;}
set
{< br> _ Title = value;
policypropertychanged ("title");
}< BR >}

Public String _ intro;
Public String intro
{< br> get {return _ intro ;}
set
{< br> _ intro = value;
policypropertychanged ("Intro");
}< BR >}

Public String _ cont;
Public String cont
{< br> get {return _ cont ;}
set
{< br> _ cont = value;
policypropertychanged ("Cont");
}< BR >}

Public event propertychangedeventhandler propertychanged;
Private void policypropertychanged (string propertyname)
{
If (null! = Propertychanged)
{
Propertychanged (this, new propertychangedeventargs (propertyname ));
}
}
}

Foreground XAML:

<ListBox X: Name = "firstlistbox" margin = "0, 0,-12, 0" itemssource = "{binding items}" selectionchanged = "firstlistbox_selectionchanged">
<ListBox. itemtemplate>
<Datatemplate>
<Stackpanel margin = "432," width = "">
<Textblock text = "{binding title}" textwrapping = "Wrap" style = "{staticresource phonetextextralargestyle}"/>
<Textblock text = "{binding intro}" textwrapping = "Wrap" margin = "12,-6, 12, 0" style = "{staticresource phonetextsubtlestyle}"/>
</Stackpanel>
</Datatemplate>
</ListBox. itemtemplate>
</ListBox>

Here, the object "notepaditem" implements the "inotifypropertychanged" interface. When its attribute changes, the "propertychanged" event is triggered. This involves "delegation", "Events", and "interfaces ". It is a little abstract to understand, and I will summarize it in detail below.

Latest Materials

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.