A friend asked me a few days ago how to dynamically bind the timeline item, that is, the piovtitem item is dynamic, and the data in the timeline titem is also dynamic. The mvvm mode can be easily implemented. In viewmodel, a set is set to indicate the number of items currently in use. The classes in the Set contain the data source in the currently available titem. The following is a simple demo:
First, let's take a look at how to bind in XAML.
<! -- Layoutroot is the root grid where all page content is placed --> < Grid X : Name = "Layoutroot" Background = "Transparent"> <! -- Modify control --> < Controls : Bytes Title = "My application" Itemtemplate = "{ Staticresource Dt_timeout }" Headertemplate = "{ Staticresource Dt_header }" Itemssource = "{ Binding Binddata } "> </ Controls : Bytes > </ Grid >
The metadata data source is bound to binddata in viewmodel. itemtemplate indicates the metadata titem template, and headertemplate indicates the header template in the metadata titem. The two templates are as follows:
< Phone : Phoneapplicationpage. Resources > < Datatemplate X : Key = "Dt_pivot"> < ListBox Itemssource = "{ Binding Listdata } "> < ListBox. itemtemplate > < Datatemplate > < Textblock Text = "{ Binding } "/> </ Datatemplate > </ ListBox. itemtemplate > </ ListBox > </ Datatemplate > < Datatemplate X : Key = "Dt_header"> < Textblock Text = "{ Binding Name } "/> </ Datatemplate > </ Phone : Phoneapplicationpage. Resources >
Headertemplate is very simple. It uses a textblock to represent the current title. Put a ListBox in the itemtemplate of the notebook. The data source is listdata under binddata.
Data Source in viewmodel:
PrivateObservablecollection<Testbench> _ Binddata;PublicObservablecollection<Testbench> Binddata {Get{Return_ Binddata ;}Set{_ Binddata =Value; Raisepropertychanged ("Binddata");}}
Testbench is a self-defined class that contains the piovtheader and javastitem data sources:
Public classTestbench{/// <Summary> ///Property for Authorization Header/// </Summary>Public StringName {Get;Set;}/// <Summary> ///Data for each item datasource (eg. ListBox)/// </Summary>PublicList<String> Listdata {Get;Set;}}
OK, the binding has been established, and now it is how to initialize the data source. For the sake of simplicity, generate the binding source data in the simplest cycle:
Public void adddata ( int size) {binddata = New observablecollection test.pdf (); for ( int I = 0; I
testbench T =
New
test.pdf (); T. name =
"piovt item" + I; T. listdata =
New
List
string ();
for (
int J = 0; j <10; j ++) {T. listdata. add (
"list item" + J);} binddata. add (t) ;}}
Here, size indicates that there are several latest titem data sources. Here, the future data source can be synchronized or asynchronously. As long as testbench implements policypropertychanged, and the attribute listdata notification changes.
You can findSource code, Hope that helps.