Silverlight 3 toolkit-autocompletebox

Source: Internet
Author: User
Tags visual studio 2010

The autocompletebox (ACB) control is like Google's search box. It helps users find similar query items (figure 1). This article describes some attributes and instances involved in the demo below. If the ACB control appears in the assets menu after toolkit is installed with blend (Figure 2), add reference: Microsoft in. windows. controls. DLL and system. windows. to use the control.

Figure 1 Figure 2

 

Demo:

 

MinimumpopulatedelayThis attribute is measured in milliseconds (the default value is 0). It is used to delay the ACB response time. The matching information is displayed n seconds after the input text.

MinimumprefixlengthIt is used to adjust the minimum number of characters entered (the default value is 1). After n characters are entered, ACB starts to match the data.

IstextcompletionenabledIf this attribute is set to true, the entered information will be matched, and the "first" most consistent item will be automatically filled in the input box (the following comparison chart ).

False true

FiltermodeIt is used to adjust the matching mode of the search (startswith by default). The related mode is as follows:

ItemssourceIs an ienumerable used to fill the control with data. The data of the first ACB in the demo is as follows:

 
Autocompletebox. itemssource =New String[] {"Microsoft Windows 7","Microsoft Expression blend","Microsoft Silverlight","Silverlight toolkit","Silverlight SDK"};

 

ItemtemplateYou can customize the display style for ACB (the second ACB effect in the demo). This is used to fill ACB with three groups of data at the same time: ID, product name, and company name.ValuememberpathTell ACB to match the group of data:

 <  Input  :  Autocompletebox  X  :  Name  = "Autocompleteboxwithstyle"  Filtermode  = "Contains"
Valuememberpath = "Productname"> < Input : Autocompletebox. itemtemplate > < Datatemplate > < Grid Width = "260" Background = "# Ff281f1f"> < Grid. columndefinitions > < Columndefinition Width = "60"/> < Columndefinition Width = "200"/> </ Grid. columndefinitions > < Grid. rowdefinitions > < Rowdefinition /> < Rowdefinition /> </ Grid. rowdefinitions > < Textblock Horizontalalignment = "Left" Foreground = "Gray"
Text = "{ Binding ID }" Grid. Column = "0" Grid. Row = "0"/> < Textblock Horizontalalignment = "Center" Foreground = "White"
Text = "{ Binding Productname }" Grid. Column = "1" Grid. Row = "0" Fontsize = "12"/> < Textblock Horizontalalignment = "Right" Foreground = "Gray"
Text = "Microsoft" Grid. Column = "1" Grid. Row = "1"/> </ Grid > </ Datatemplate > </ Input : Autocompletebox. itemtemplate > </ Input : Autocompletebox >

 

Use the microsoftproducts. CS class to fill data with ACB through list <t>:

 List < Microsoftproducts > Productlist = New  List < Microsoftproducts > (); Productlist. Add ( New  Microsoftproducts () {Id = 1, productname = "Windows XP" }); Productlist. Add ( New  Microsoftproducts () {Id = 2, productname = "Windows 7" }); Productlist. Add (New  Microsoftproducts () {Id = 3, productname = & Quot; SQL Server 2008 & quot" }); Productlist. Add ( New  Microsoftproducts () {Id = 4, productname = & Quot; Visual Studio 2010 & quot" }); Productlist. Add ( New  Microsoftproducts () {Id = 5, productname = "Silverlight 3" }); Productlist. Add ( New  Microsoftproducts () {Id = 6, productname ="Expression blend 3" }); Productlist. Add ( New  Microsoftproducts () {Id = 7, productname = "Silverlight 4" }); Productlist. Add ( New  Microsoftproducts () {Id = 8, productname = "Windows Vista" }); Autocompleteboxwithstyle. itemssource = productlist;

 

The third ACB uses the DataGrid display effect, adds the datagridselectionadapter. CS class, and addsProgramNamespace xmlns: samples = "CLR-namespace: silverlighttoolkit", write style for ACBCode(See source program ):

<Input:AutocompleteboxX:Name= "Autocompleteboxwithdatagrid"Verticalalignment= "Bottom"
Filtermode= "Contains"Valuememberpath= "Productname"Style= "{StaticresourceAutocompleteboxdatagridtemplate}"/>

 

Fill in data through objectcollection (you need to add system. Windows. Controls. toolkit. dll ):

 Objectcollection Productdatagrid = New  Objectcollection (); Productdatagrid. Add ( New  Microsoftproducts () {Id = 1, productname = "Windows XP" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 2, productname = "Windows 7" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 3, productname = & Quot; SQL Server 2008 & quot" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 4, productname = & Quot; Visual Studio 2010 & quot" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 5, productname = "Silverlight 3" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 6, productname = "Expression blend 3" }); Productdatagrid. Add ( New Microsoftproducts () {Id = 7, productname = "Silverlight 4" }); Productdatagrid. Add ( New  Microsoftproducts () {Id = 8, productname = "Windows Vista" }); Autocompleteboxwithdatagrid. itemssource = productdatagrid;

 

Source codeDownload:

 

References:

Autocompletebox control: the missing guide

Introducing the autocompletebox

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.