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