Over a million developers have joined DZone.

Using Custom Objects in RadAutoCompleteBox for Windows Phone

· Mobile Zone

In one of my earlier blog posts, I talked about RadAutoCompleteBox showing how to display suggestions using a List of strings.

I had a requirement to bind custom objects to the Suggestion List to the RadAutoCompleteBox and it took the help of the Telerik Support Team to get it done.

To put it simply, Telerik’s Support Team is super .

To bind the Custom Business Objects , you should follow 3 steps

1. Set the SuggestionsSource to the List of Custom Objects

2. Set the FilterKeyPath

3. Create SuggestionItemTemplate and DataTemplate and bind the property that should be displayed as a suggestion.

Below is a sample sourcecode that uses Custom Objects to display Suggestion.

<telerikInput:RadAutoCompleteBox Height="70" HorizontalAlignment="Left" Margin="17,31,0,0" Name="radAutoCompleteBox1" Text=""
VerticalAlignment="Top" Width="429" FilterKeyPath="Name"  >
<telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>
<DataTemplate>                   �
<TextBlock Text="{Binding Name}"/>               �
</DataTemplate>               �
</telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>           �
</telerikInput:RadAutoCompleteBox>
public partial class MainPage : PhoneApplicationPage   �
{       �
// Constructor       �
public MainPage()       �
{           �
InitializeComponent();           �
radAutoCompleteBox1.SuggestionsSource = Data.GetSuggestions();       �
}    �
}   �
public class Employee   �
{       �
public string Name       �
{           �
get;           �
set;       �
}

public string ID       �
{           �
get;           �
set;       �
}

}   �
public static class Data   �
{       �
public static List<Employee> GetSuggestions()       �
{           �
List<Employee> Names = new List<Employee>();           �
Names.Add(new Employee { Name = "Vijay", ID = "1" });           �
Names.Add(new Employee { Name = "Senthil", ID = "2" });           �
Names.Add(new Employee { Name = "Surya", ID = "3" });           �
Names.Add(new Employee { Name = "Norton", ID = "4" });           �
Names.Add(new Employee { Name = "Sandy", ID = "5" });           �
Names.Add(new Employee { Name = "Saravan", ID = "6" });           �
Names.Add(new Employee { Name = "Sunil", ID = "7" });           �
 return Names;       �
}   �
}



 

Topics:

Published at DZone with permission of Senthil Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}