Windows 8 Development-items elements in ListBox

Source: Internet
Author: User

The items set in ListBox is the ing of the itemssource set. The following statements and definitions are provided in the API:

 
//// Summary: // obtain the set used to generate the control content. //// Return result: // if there is a set used to generate the control content, it is the set; otherwise, it is null. The default value is an empty set. Public itemcollection items {Get ;}

If itemssource of ListBox is list <long>, items is the list <long> type. If it is observablecollection <someclasstype>, items is the set of this type.

Through items, in addition to viewing the use of the data source, what can be done? The following describes how to use items to set the default multi-choice status when initializing ListBox.

Although it is a relatively small feature, it is worth understanding. The following is an example:

(1) first create The ListBox data source, which is a collection of listboxitem types.

 
List <listboxitem> items = new list <listboxitem> (); For (INT I = 1; I <= 12; ++ I) {items. add (New listboxitem () {content = I}); // the actual data used will be integer I, included in the content of ListBox} monthlb. itemssource = items;

(2) define a Public Member and set the get and set accessors to get the selected listboxitem and initialize the selected items.

Public list <int> selectedmonths {get {list <int> months = new list <int> (); foreach (listboxitem item in monthlb. items) {If (item. isselected) // The listboxitem is selected {months. add (INT) item. content) ;}} return months;} set {If (value = NULL | value. count = 0) {foreach (VAR item in monthlb. items) (item as listboxitem ). isselected = true;} else {If (value = NULL) {monthlb. itemssource = NULL; return;} foreach (VAR index in value) {If (index <0) Index = 0; // set isselected = true for the listboxitem, is selected (monthlb. items [Index] As listboxitem ). isselected = true ;}}}}

(3) set the selectionmode attribute of ListBox to the check status, that is, selectionmode = "multiple ". In this way, you can check and initialize multiple ListBox selections.

There may be a better way, but I didn't find it; if anyone knows, please tell me.
~ _~

Related Article

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.