DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Databinding an Auto Complete Box in Windows Phone

Databinding an Auto Complete Box in Windows Phone

Senthil Kumar user avatar by
Senthil Kumar
·
Nov. 16, 11 · Mobile Zone · Interview
Like (0)
Save
Tweet
6.32K Views

Join the DZone community and get the full member experience.

Join For Free

The Auto Complete Box is one of the controls that is a part of the Silverlight Toolkit for Windows Phone, which just got a new release this week!

 

One of the features of the AutoCompleteBox is that when a user types a character or keyword , the control will show the related words in the drop down list .

 

To add the Auto Complete Box , make sure you have installed the Silverlight Toolkit for Windows Phone and added the Silverlight Toolkit controls to the toolbox .

 

Just Drag and Drop the control "AutoCompleteBox" from the toolbox to the xaml page

20111114_1.jpg

 

The XAML code for the Auto Complete Text box will look like this

<toolkit:AutoCompleteBox Grid.Row="1" Height="80" HorizontalAlignment="Left" Margin="41,156,0,0" Name="autoCompleteBox1" VerticalAlignment="Top" Width="403" />

 

Alternatively you can also create the Auto Complete Box in the Code Behind form .

 

1. Add the namespace - Microsoft.Phone.Controls namespace . Make sure that the Microsoft.Phone.Controls.Toolkit assembly is added via Add Reference

 

2. Define the Data i.e List of String and assign the data to the ItemSource property of the AutoComplete object and add the AutoCompleteBox to the container (StackPanel) .

public void AddAutocomplete()
{
             AutoCompleteBox txtbox = new AutoCompleteBox();
            stack.Children.Add(txtbox);
            // Data
            txtbox.ItemsSource = GetSports();
}
 
public List<string> GetSports()
{
            List<string> Sports = new List<string>();
            Sports.Add("Cricket");
            Sports.Add("Tennis");
            Sports.Add("Table Tennis");
            Sports.Add("Hockey");
            Sports.Add("Football");
            return Sports;
}

 

Now , Run the Windows Phone App and start typing first few charcters in the AutoCompleteBox . You should see the list of Suggestions based on the set of data provided as ItemSource .

 

20111114_2.jpg

 



Source: http://windowsphonerocks.com/Developer/DeveloperArticles/tabid/64/Article/224/databinding-an-auto-complete-box-in-windows-phone.aspx
Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 7 Traits of an Effective Software Asset Manager
  • Comprehensive Guide to Jenkins Declarative Pipeline [With Examples]
  • Take Control of Your Application Security
  • A Developer Evangelist's Thoughts on Angular 2

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo