Reverse Filtering in AutoCompleteBox in Windows Phone

The AutoCompleteBox in Silverlight ToolKit for Windows Phone lets you perform the custom logic to display the list of Suggestions matching the typed characters .

For example , you could use the write your logic to show the suggested words in reverse order .

Assume , you have a list of Suggested word as Tennis , when the user types si , the Tennis as suggestion might be required to be shown and this blog post will explain how to that …

Reverse Filtering in AutoCompleteBox in Windows Phone

The AutoCompleteBox has the property ItemFilter which accepts a custom method that will be used to filter the suggested words based on our own logic .

The ItemFilter is of delegate and accepts 2 parameters – one is the search string and other is the item to be compared with . This returns true is the word matches .

Below is the sample sourcecode to do the reverse filtering in the AUtoCompleteBox in Windows Phone .

public partial class MainPage : PhoneApplicationPage

{

// Constructor

public MainPage()

{

InitializeComponent();

}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)

{

autoCompleteBox1.ItemsSource = new Sports();

autoCompleteBox1.MinimumPrefixLength = 2;

autoCompleteBox1.ItemFilter = ReverseFilter;

}

private bool ReverseFilter(string SearchString, object Lst)

{

if (Lst != null)

{

string s = SearchString.ToString();

char[] arr = s.ToCharArray();

Array.Reverse(arr);

if (Lst.ToString().ToLower().EndsWith(new string(arr)))

return true;

}

return false;

}

}

class Sports : List<string>

{

public Sports()

{

Add("Cricket");

Add("Tennis");

Add("Football");

Add("Table Tennis");

Add("Chess");

Add("Base Ball");

}

}

 

httpv://www.youtube.com/embed/LoEjbWy6RDs

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...