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

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...