Using the BPC SearchBox Control

The SearchBox control is a part of Bewise Phone Controls current release. To use it, add the BPC library to your project. 

The SearchBox control is made of a single textbox with a search button. It exposes a Search event that will be raised when the button is clicked.

You just have to subscribe to this event to perform any logic you want on a list. The SearchBox control has a Filter property which is actually the textbox content.

 

<StackPanel Margin="10">
    <Bewise:SearchBox Name="searchBox1"  />
    <ListBox x:Name="lbPersons" DisplayMemberPath="Name"></ListBox>
</StackPanel>

 

The SearchBox control also has a public method DoFilter that helps you manage filtering .

DoFilter takes a string value as parameter and return true if the text in the SearchBox is contained into the parameter value.

Here is a simplified example of how you can filter a list when the search button is clicked (the full example can be found in the ControlSamples application):

 

IEnumerable<Person> allPersons ;
searchBox1.Search += new EventHandler(searchBox1_Search);

void searchBox1_Search(object sender, EventArgs e)
{
    // implement your logic here
    IEnumerable<Person> filteredList = allPersons.Where(p => searchBox1.DoFilter(p.Name));       
}

And here is what the SearchBox Control looks like, with a listbox below that contains the filtered list of persons:

Properties:

Filter: represents the text value inside the searchbox

HasFilter: returns true if Filter is not null or empty

 

Methods:

DoFilter: returns true if the parameter value contains the filter text

Show : displays the SearchBox

Hide : Hide the SearchBox


Last edited May 8, 2011 at 9:04 PM by Anael974, version 4

Comments

No comments yet.