SIGN UP MEMBER LOGIN:    
ARTICLE

AutoCompleteBox in Silverlight 3

Posted by Praveen Kumar Articles | Silverlight September 02, 2009
In this article we will see how to load AutoCompleteBox with sample date in Blend 3 in our silverlight application.
Reader Level:
Download Files:
 


In this article we will see how to load AutoCompleteBox with sample date in Blend 3 in our silverlight application.

Open Blend 3 and name your project. Here the project name is "AutoCompleteBoxinSL".

Let's start by creating a sample data for our application. For creating a sample data, click on the data tab and select "Define New Sample Data".


1.gif

Give some name to your data source name as shown below:


2.gif

The default structure of your source will look like this:


3.gif

After some changes, it will look like this:


4.gif

To enter some values in our fields click on the icon shown below:


5.gif

We will get the "Edit Sample Values" window which allows us to enter values to our predefined fields. The figure is shown below:


6-1.gif

Now we have created our sample data and ready to be consumed in our application.

Drag a AutoCompleteBox control to our work area. You can see the control if you aleady installed the "Silverlight Toolkit". If not, you can do it from here.

Now all you have to do is to drag the sample collection to our control.


7.gif

Our task is not finished yet. You will not be getting the desired result by running the application.

Simply drag the sample collection to your work area.


8.gif
This will create a ListBox with the data source name as created by us.

9.gif

Now set the ItemTemplate of our AutoCompleteBox as shown below:


10.gif

Now you can delete the autogenerated ListBox.

The code for our AutoCompleteBox will look like this.

<
input:AutoCompleteBox Margin="18,38,0,0" VerticalAlignment="Top" ItemsSource="{Binding Sample}" DataContext="{Binding}" ItemTemplate="{StaticResource SampleItemTemplate}" HorizontalAlignment="Left" Width="278" />

Now open the SampleDataSource.xaml.cs file and do the changes shown below

public
override string ToString()
{

    return
a1;
}

Also some changes are made in this file for the desired output.

Like for showing the area in this format we have made changes as shown below:

public
string a3
{
         
get
          {
                  
return "Area: " + this._a3 + " Sq. Km.";
          }
         
set
          {
                  
if (this._a3 != value)
                   {
                            
this._a3 = value;
                            
this.OnPropertyChanged("a3");
                   }
          }

}

The final product will look like below after some styling for our control:

11.gif

I am not going through the styles in this article. You can refer the source code attached with this article.

Note
: The figures shown in this example is only for demonstration purpose.

share this article :
post comment
 

hi,

its nice article..
We tried this and able to get it..We would like to add hyperlink as additional metadata..meaning..some keyword and hyperlink for that keywork...
we are able to display in autocompletebox, we want to make it as clickable..
when we select any keyword..we should be able to click the hyperlink..can u suggest how to get it?

thanks,
xxx

Posted by sharavathi Jun 14, 2010

good article keep going.

Posted by Raj Kumar Sep 03, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor