WPF: use additional attributes to record ListBox/listview selection information

Source: Internet
Author: User

You can use this type of additional property to quickly record the selection information of ListBox/listview on the interface.

This type is called listcounter and has three additional attributes:

ListBox: Specifies the target ListBox or listview.

Property: string type, which specifies the attributes of the current object to be set.

Formatstring: string type. Optional (because of the default value). The format string is specified. {0} indicates the number of all elements, and {1} indicates the number of selected elements.

 

It is easy to use, for example:

<ListBox name = "lbx" selectionmode = "extended"/>

<Textblock LOC: listcounter. ListBox = "{binding elementname = lbx }"

Loc: listcounter. Property = "text"/>

 

Result:

 

The text attribute of textblock is set to the selection information of ListBox.

Of course, you can add custom format strings or set other attributes:

<ListBox name = "lbx" selectionmode = "extended"/>

<! -- Set the content of the button -->

<Button name = "TBL"

Loc: listcounter. formatstring = "{}{ 1}/{0 }"

Loc: listcounter. ListBox = "{binding elementname = lbx }"

Loc: listcounter. Property = "content"/>

 

Preview:

 

Source code download

Note: This is an archive of Microsoft SkyDrive. Please download it directly in your browser. Some download tools may not be available for download.

File Type:. CS File

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.