As mentioned in Windows Phone 7 tips (5), the page layout in Windows Phone 7 is generally divided into panoramic, screens, list, and full screen. Generally, ListBox is the implementation method of list.
1. What is ListBox?
ListBox is a control of the display item set. Multiple items in ListBox can be displayed at a time.
ListBox inherits from itemscontrol. You can use items or itemssource to set its content.
2. display data in ListBox
We can use two methods to display in ListBox: directly embedding listboxitem (or other uielements, such as textblock) and data binding (in 90% cases, data binding is implemented ).
1. Directly embed the ListBox exampleCodeAs follows:
2. The sample code for data binding is as follows:
XAML code:
Post Code:
The actual results are the same, for example:
3. If you obtain the control specified in itemtemplate/datatemplate of ListBox
When we use data-bound controls, such as ListBox, we usually customize the ListBox template (we generally recommend that you use the blend tool to modify the template). In some cases, we need to obtain a control in datatemplate to perform some specific operations on it. How can we get it? In fact, we can use the visualtreehelper class to obtain the specified control. The following is a demo:
Front-end XAML code:
Post Code:
Iv. ListBox Performance
InSilverlightTo display data to users, we need to load data and bind data. But which of the following causes performance problems? The answer is: Based on your data type and interface (UI.
Generally, data can be loaded inUIIn the thread or background thread, the data format is not the same, some are serialized as binary data, and some are serializedXMLFile, some are images, and so on. Data Binding has three different binding forms: one binding (One time), One-way binding (One way) And bidirectional binding (Two Way).
What isVSP(Virtualizingstackpanel)
msdn arrange and virtualize the content on one row in either horizontal or vertical directions. "Virtualization" refers to a technology that can generate a large number of data items based on the items displayed on the screen. User Interface (UI) subset of elements. Only when stackpanel contains the item control to create its own item container, virtualization will occur in this panel. you can use data binding to ensure that this process occurs. If you create an item container and add it to the item control, compared with stackpanel , virtualizingstackpanel it cannot provide any performance advantages.
virtualizingstackpanel Yes ListBox default item host of the element. by default, isvirtualizing set the property to true . When isvirtualizing is set to false , virtualizingstackpanel behavior and common stackpanel same.
We canVSPIt is understood that when necessary,VSPThe container object is generated, and when the object is not within the visible range,VSPRemove these objects from the memory. WhenListBoxI really want to solve the memory problem when we do not need to load objects out of the visible range into the memory when there is a large amount of data in the project. In additionVSPThere is an attributeCachemodeSets the cache representation. The default value isStandard. You can set itReconfiguring.
InListBoxUsed inVSPFor data virtualization, we need to pay attention to the following points:
1.Make sure thatDatatemplateContainers (suchGrid) Fixed size
2.When the data object can provide the corresponding value, try to avoid using a complex converter (Converter)
3.Do notListBoxEmbedded inListBox
4.We strongly recommend that you do notDatatemplateUse User Controls
5.InDatatemplateDo not use custom controls
The above is a brief introduction to ListBox. In the future, we will continue to go deep into ListBox.